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

When using a Jenkins pipeline, is there a way to get the user that responded to an input() action?

考虑以下示例

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 中使用的变量中可用?

将字段 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']}"