【问题标题】:Jenkins Pipeline - conditional execution with branch and 1 other parameter (manual)Jenkins Pipeline - 使用分支和 1 个其他参数的条件执行(手动)
【发布时间】:2021-08-08 17:43:06
【问题描述】:

我们正在像这样使用 Jenkins 管道部署我们的应用程序 -

pipeline {
  agent any
  stages {
    stage('Build For Production') {
        when { branch 'development' }
        steps {
             sh './bin/build.sh'
        }
    }
    stage('Build For Production') {
        when { branch 'master' }
        steps {
             sh './bin/copy_needed_auth.sh'
             sh './bin/build.sh'
        }
    }
  }
}

当开发人员在 bitbucket 上推送代码时,应用程序会自动部署。使用分支,我们设置我们的部署策略。

when { branch 'master' }

但是我们需要为在生产(主分支)上部署设置手动检查,例如 - 当开发人员将合并主分支中的代码时,他还将设置一些标签或类似的东西,以便 Jenkins 管道将检查分支 +在生产中部署的其他手动逻辑。

我们正在这样做 -

when { 
    branch 'master' 
    tag: 'release-*'
}

但它不起作用。有没有其他策略可以做到这一点?

【问题讨论】:

    标签: jenkins jenkins-pipeline devops


    【解决方案1】:

    使用以下代码来使用多个when 条件:

    when { 
      allOf { 
        branch 'master'; 
        tag "release-*"
      }
    }
    

    相关文档你可以找到here

    【讨论】:

    • 它不起作用,Jenkins 文件输出 - 由于条件条件而跳过了阶段“为生产而构建”
    • 因为条件只有在 branch = master 并且您将 tag 设置为 release-* 时才有效。如果您需要满足至少一个条件而不是所有条件,则使用 'anyof' 而不是 'allof'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    • 1970-01-01
    • 2018-02-10
    • 1970-01-01
    • 2022-11-24
    相关资源
    最近更新 更多