I am using the Pipeline plugin in Jenkins by Clouldbees (the name was Workflow plugin before), I am trying to get the user name in the Groovy script but I am not able to achieve it.
stage 'checkout svn'
node('master') {
// Get the user name logged in Jenkins
}
Did you try installing the Build User Vars plugin? If so, you should be able to run
or similar.
Here's a slightly shorter version that doesn't require the use of environment variables:
The use of
rawBuild
requires that it be in a@NonCPS
block.I modified @shawn derik response to get it to work in my pipeline:
Then I can reference that variable later on by passing it or in the same scope as ${GET_BUILD_USER} . I installed the same plugin referenced.
To make it work with Jenkins Pipeline:
Install user build vars plugin
Then run the following:
It is possible to do this without a plugin (assuming
JOB_BASE_NAME
andBUILD_ID
are in the environment):There is also a getUserName, which returns the full name of the user.