使用Jenkins管道时,有没有办法让用户响应input()动作?

时间:2017-03-01 16:56:32

标签: jenkins jenkins-plugins jenkins-pipeline

考虑以下示例

node {
    stage('Build') {
        echo "do buildy things"
    }

    stage('Deploy') {
        hipchatSend(
            color: "PURPLE",
            message: "Holding for deployment authorization: ${env.JOB_NAME}, job ${env.BUILD_NUMBER}. Authorize or cancel at ${env.BUILD_URL}",
        )
        input('Push to prod?') //Block here until okayed.
        echo "Deployment authorized by ${some.hypothetical.env.var}"
        echo "do deploy things"
     }
}

响应输入时,单击该按钮的用户名将存储在构建日志中。

这个用户名是否可以在我可以用于另一个hipChatSend的变量中使用?

1 个答案:

答案 0 :(得分:1)

将字段submitterParameter提供给input

def userName = input message: '', submitterParameter: 'USER'
echo "Accepted by ${userName}"

如果您没有任何参数,submitterParameter的值无关紧要。但是如果你有参数,那么它将指定包含值的数组元素的名称:

def ret = input message: '', parameters: [string(defaultValue: '', description: '', name: 'para1')], submitterParameter: 'USER'
echo "Accepted by ${ret['USER']}"