Jenkins多分支管缐建置后仅限特定分支(宣告式)

7nbnzgx9  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(206)

如何创建在每个分支上执行其阶段,而只在特定分支上执行后期生成操作的管道?
我已经看到了when {branch 'production'}选项,但在我看来,这只适用于stage块,而不适用于post块。

pipeline {
  agent { any }
  stages {
    stage('build') {
      steps {
        bat script:"echo build" 
      }
      post {
        always {
          when {
            branch 'production'
          }
          bat script:"echo publish"
        }
      }
    }
  }
}

if (env.BRANCH_NAME == 'production')似乎只适用于脚本化的管道

czq61nw1

czq61nw11#

Conditional post section in Jenkins pipeline有一个答案:在后置条件中使用scriptif

post {
        always {
            script {
                if (env.BRANCH_NAME == 'production') {
                    // I have not verified whether your step works here;
                    // conditional emailext works as expected.
                    bat script:"echo publish"
                }
            }
        }
    }

相关问题