Mikey T.K.
Mikey T.K.

Reputation: 1160

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

Consider the following example

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"
     }
}

When responding to the input, the user name that clicked the button is stored in the build log.

Is this username made available in a variable that I could use in, say, another hipChatSend?

Upvotes: 4

Views: 2776

Answers (1)

Jon S
Jon S

Reputation: 16346

Supply the field submitterParameter to input:

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

The value of submitterParameter doesn't matter if you doesn't have any parameters. But if you have parameters, then it will specify the name of the array element which holds the value:

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

Upvotes: 6

Related Questions