samrocketman / jenkins-bootstrap-jervis

An automated Jenkins CI environment which provisions agent infrastructure on the fly per build.
Apache License 2.0
75 stars 30 forks source link

Get user who triggerred Job DSL build #18

Open samrocketman opened 6 years ago

samrocketman commented 6 years ago

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