Jenkins 詹金斯条件阶段

Jenkins 詹金斯条件阶段,jenkins,continuous-integration,devops,Jenkins,Continuous Integration,Devops,我使用的是声明性Jenkins管道。我有一个阶段,从用户那里获得输入,比如 //Input stage ('Manual Input'){ agent none steps { input message: "Please Approve", ok: 'Approve' } } 我不想让任何代理在Jenkins等待手动步骤完成时被耽搁,因此我使用了agent none 我想知道是否有一种方法,这个阶段有条

我使用的是声明性Jenkins管道。我有一个阶段,从用户那里获得输入,比如

//Input 
    stage ('Manual Input'){
        agent none
        steps {
            input message: "Please Approve", ok: 'Approve'
        }
    }
我不想让任何代理在Jenkins等待手动步骤完成时被耽搁,因此我使用了
agent none

我想知道是否有一种方法,这个阶段有条件地执行

详细说明这一点:

pipeline {
agent none

parameters {
    choice(choices: "No\nYes",
        description: 'Choose Yes to wait for Manual Input',
        name: 'Input')
}
stages {

    stage ('Stage_1'){
        agent any
        steps {
           //Some Steps here
        }
    }

    //Input stage which should only get executed if ${Input} is Yes
    // Or else Directly go to Stage 3

    stage ('Manual Input'){
        agent none
        steps {
            input message: "Please Approve", ok: 'Approve'
        }
    }

stage ('Stage_3'){
        agent any
        steps {
           //Some Steps here
        }
    }
}
}
我希望Jenkins执行“Stage_1”,然后仅当参数“Input”为“Yes”时才执行Stage“Manual Input”,否则跳过Stage“Manual Input”进入“Stage_3”

我无法在“手动输入”阶段的
script{}
块中执行
if/else
,因为
agent none
。它抛出了一个错误


非常感谢你的帮助!TIA

基本上,您所要做的就是在第二阶段的语句中添加一个
,您希望它看起来像这样:

stage ('Manual Input'){
    agent none
    when{
        expression { params.Input == 'Yes' }
    }
    steps {
        input message: "Please Approve", ok: 'Approve'
    }
}
你可以找到关于这个的文档。(您将看到,对于这种特定情况,
equals
更合适)