Jenkins检查env.BRANCH_NAME是否在Post Section中包含一些关键字

问题描述 投票:1回答:1

我需要跳过某些包含“HotFix”作为单词的分支。是否有可能在Jenkins文件中有类似下面的内容?

post {
    success {
        withCredentials(some_details) {
            script {
                try {
                    if (!env.BRANCH_NAME.contains('HotFix')) {

                    }
                    else {

                    }
                }
                catch (err) {
                    echo    err
                }
            }
        }
    }
}
jenkins jenkins-pipeline
1个回答
2
投票

Jenkins Declarative管道支持when directive,它可以根据预定义的条件跳过某些阶段。请考虑以下示例:

pipeline {
    agent any

    stages {
        stage("A") {
            steps {
                // ....
            }
        }

        stage("B") {
            when {
                expression {
                    !env.BRANCH_NAME.contains("HotFix")
                }
            }
            steps {
                // ....
            }
        }
    }
}

在这种情况下,我们只想在当前分支名称不包含B时执行阶段HotFix

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.