【问题标题】:Conditional step in JenkinsfileJenkinsfile 中的条件步骤
【发布时间】:2021-11-24 15:12:58
【问题描述】:

我有以下情况:

.
.
.
stage('My stage')
{
  steps
  {
    sh 'my_command1.sh'
    sh 'my_command2.sh'
    sh 'my_command3.sh'
  }
}
.
.
.

只有在特定条件下才能执行步骤“my_command2.sh”?我知道可以用“when”标记定义条件语句,但条件对所有阶段都有影响。我只想将此行为限制为一个步骤。

谢谢。

【问题讨论】:

    标签: jenkins jenkins-pipeline conditional-statements


    【解决方案1】:

    您可以使用script 那么你的舞台会是这样的:

    stage('My Stage') {
        steps {
           script{
               sh 'my_command1.sh'    
               if(condition){
                   sh 'my_command2.sh'           
               }
               sh 'my_command3.sh'   
               }
            }
        }
    

    您也可以从official documentation查看声明性步骤

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-15
      • 1970-01-01
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      相关资源
      最近更新 更多