jenkins-bootstrap-jervis
jenkins-bootstrap-jervis copied to clipboard
Get user who triggerred Job DSL build
There's two ways.
The user who caused the build is stored in a variable.
println "JENKINS_USER: ${JENKINS_USER}"
A more manual method for determining the user who triggered the Job DSL build. SEED_JOB is a binding for the current instance FreeStyle job. BUILD_NUMBER is a binding of the current running build (is a String).
import hudson.model.Cause.UserIdCause
triggered_by_userid = SEED_JOB.getBuildByNumber(BUILD_NUMBER as int).getCause(UserIdCause.class).getUserId()
println "Actual user: ${triggered_by_userid}"