twasbrillig
twasbrillig

Reputation: 18921

How to get the Jenkins plugin Build User Vars to work with Jenkins Pipeline

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.

Upvotes: 3

Views: 7892

Answers (1)

Tayguara Dias Reis
Tayguara Dias Reis

Reputation: 61

try use this variable:

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

I used here and It worked !!

Upvotes: 4

Related Questions