Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know which user answered a Jenkins-Pipeline input step?

I have a Jenkinsfile script that tests for the possibility to perform an SVN merge and then asks the user for the permission to commit the merge.

I would like to know the username that answers the "input" step in order to write it into the commit message.

Is this possibile?

This is what hypothetically I would like to do:

outcome = input message: 'Merge trunk into branch?', ok: 'Merge'
echo "User that allowed merge: ${outcome.user}"
like image 904
Federico Bonelli Avatar asked Sep 12 '16 13:09

Federico Bonelli


2 Answers

The input step got an optional submitterParameter, which allows to specify the key of the returned Map that should contain the user who's submitting the input dialog:

If specified, this is the name of the return value that will contain the ID of the user that approves this input.
The return value will be handled in a fashion similar to the parameters value.
Type: String

This looks then as follows:

def feedback = input(submitterParameter: 'submitter', ...)
echo "It was ${feedback.submitter} who submitted the dialog."

P.S: If anybody is interested in a full-fledged code snippet returning the user both for positive and negative feedback to the dialog (and timeout as well), I kindly point to our pipeline library.

like image 132
StephenKing Avatar answered Oct 03 '22 08:10

StephenKing


It is not currently possible, for now only entry parameters are returned in the input step answer, as mentionned in source code :

// TODO: perhaps we should return a different object to allow the workflow to look up
// who approved it, etc?
switch (mapResult.size()) {
case 0:
    return null;    // no value if there's no parameter
case 1:
    return mapResult.values().iterator().next();
default:
    return mapResult;
}

If you'd like to restrict which user(s) can approve the input step, you can however use the submitter parameter, e.g. :

input message: 'Approve ?', submitter: 'authorized-submitter'

EDIT

Since January 2017 it is now possible to request additional parameters to be sent. Please see StephenKing answer above.

like image 22
Pom12 Avatar answered Oct 03 '22 08:10

Pom12