1
votes

I'm using this Jenkins plugin: https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin

With this plugin installed, if you check the box "Set jenkins user build variables", you can use the environment variable ${BUILD_USER} which gives the name of the person who built the Jenkins job.

But, I can't get the plugin to work with the Pipeline plugin (https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin).

I noticed that checking that "Set jenkins user build variables" box adds the following line to the config.xml of your Jenkins job: <org.jenkinsci.plugins.builduser.BuildUser plugin="[email protected]"/>

So I tried the following:

import org.jenkinsci.plugins.builduser.BuildUser
echo "${env.BUILD_USER}"

But it prints out null.

1
I'm not fluent in groovy, but you can try to write in groovy smth like : wget $BUILD_URL -O- | xmllint --html --xpath "//*/table/tr[2]/td[2]/p/span/a/text()" - , which means go to the build page, and parse to get a user (Note: in order to try the script xmllint and wget should be installed on jenkins host)yvs

1 Answers

1
votes

try use this variable:

def USER = wrap([$class: 'BuildUser']) {
     return env.BUILD_USER
}

I used here and It worked !!