Plugin Information |
---|
View user build vars on the plugin site for more information. |
This plugin provides a set of environment variables that describe the user who started the build.
Variables provided
This plugin defines the following environment variables to describe the user who started the build:
Variable |
Description |
---|---|
BUILD_USER |
Full name (first name + last name) |
BUILD_USER_FIRST_NAME |
First name |
BUILD_USER_LAST_NAME |
Last name |
BUILD_USER_ID |
Jenkins user ID |
BUILD_USER_EMAIL |
Email address |
Usage example
Select Set Jenkins user build variables and reference the variables during the build:
Jenkins core compatibility
This plugin requires Jenkins 1.609+ (since 1.5 version of plugin).
Changelog
1.5 (Dec 11, 2015)
- Workflow support
- Requires 1.609 or higher of Jenkins.
1.4 (Oct 10, 2014)
- Support of BUILD_USER_EMAIL. Currently, only the explicit e-mail definition in user properties will work (see Mailer Plugin)
- NPE on non-existent upstream builds (JENKINS-22974)
1.3 (Apr 12, 2014)
User variables are not set to Maven3 build (JENKINS-19187)
1.2
* [JENKINS-21955] Set BUILD_USER to "SCMTrigger" if a build is run because of a source code change
1.1
* Now works with Jenkins starting from 1.396 version.
1.0
* Initial version
61 Comments
Gregory Boissinot
In my opinion, it is always difficult to have again another plugin for this field.
I suggest you should look at the envinject plugin and extend it with your plugin. EnvInject plugin eanbles you to manage injected variables and keep track of variables for each build. Your plugin will extend it by adding your specific variables and could have all features provided by the envinject plugin.
Extending EnvInject plugin can be done for example with the shared-objects plugin.
Let me know if you need help.
Gavriil Konovalenko
Hi Gregory,
thx for pointing out. Agreed with you. Before implementing this I looked through EnvInject, hoping that it provides such fields.
I'll have a look.
Gregory Boissinot
Any updates?
Gavriil Konovalenko
Not yet. I've emailed you requesting if there are any example of such extension. If so, could you please share link for it?
Gregory Boissinot
Just contribute to the EnvironmentContributor extension point.
And automatically, all your environment variables will be captured by the EnvInject plugin
Hua Zhang
We run into JENKINS-12528 using started-by-envvar. Can this plugin cope with the situation?
Gavriil Konovalenko
Hi Hua,
you can give it a test try. But more likely this won't work.
This is because both plugins use User sub-types of Cause to identify the user started the build. Started-By Environment Variable Plugin uses only deprecated UserCause, Build User Vars Plugin uses both deprecated UserCause & new UserIdCause (maybe usage of second will help you).
And as per you bug report, you can see following message: "Legacy code started this job. No cause information is available"
This message is output of jenkins itself, not plugins' and means that there is no source to get Username of user started the build.
As I know there is no other way to get username, so if test try will also fail, I'd suggest you to reassign this bug (or transform to feature request) to Promoted Builds Plugin, asking to fix absence of build Cause.
Let me know if you will need further help.
Hua Zhang
I also suspected the same. Thanks for the clarification!
Martin Ba
@Gavriil Konovalenko (Plugin Implementer): Does this here plugin fully replace Started-By Environment Variable Plugin? (Apart from the different var-names of course?)
Gavriil Konovalenko
Yes, you're right -- it does the same.
Nigel Robbins
Hi,
The BUILD_USER variable is unset on downstream Solaris jobs for some reason. The initial job is on Solaris 10 which triggers jobs on Solaris 9, Solaris 10 (different host), Linux 32, Linux 64, HP Itanium, HP PA-RISC. The BUILD_USER variable is unset on the downstream Solaris 9 and 10 jobs. I've not checked the other downstream jobs (e.g. Linux 32) to see if BUILD_USER is unset.
Thanks !
Gregory Boissinot
Please could you report a bug?
Nigel Robbins
When creating a Jenkins JIRA Issue, what do I enter in the "Component/s" drop down since it doesn't seem to find "build-user-vars-plugin" ?
Thanks !
Gavriil Konovalenko
Hi Nigel.
This is not a bug. Build user could be identified only in case if build was started by user. If build was triggered by other cause, f.e. by timer or by end of upstream job -- there is no data about user, who had started the build.
Larry Cai
Are there any workaround solution to do this ?
Currently in the console, I can see the real triggered user name even it is trigggered by upstream project
Björn Kraus
Thanks for your useful plugin which IMHO is truly a missing feature in Jenkins ;-)
It would be very handy to also have the email of the user available. Is it possible for you to add this?
Thanks in advance!
jsirex -
When I use this plugin with crowd2-plugin I got incorrect BUILD_USER_ID which looks like:
I'm not sure is this issue related to your plugin or to jenkins-crowd2 plugin.
Did a little trick:
Gavriil Konovalenko
Hi jsirex,
Thanks for sharing workaround for this particular case.
Actually this isn't and issue of build-user-vars-plugin or jenkins-crowd2 plugin. This plugin simply sets BUILD_USER_ID
with appropriate value from jenkins build cause. And this value, I guess, is set by Jenkins basing on data provided by jenkins-crowd2 plugin. So it looks like from point of jenkins-crowd2 plugin view userId has format of "FirstName, LastName (login_name)."
You can address this to jenkins-crowd2 plugin developers, but I think you workaround is better option.
yury milchenko
Chuck Norris Approved!
Brilliant Plugin
Gavriil Konovalenko
Chuck Norris has commented plugin's code: https://github.com/jenkinsci/build-user-vars-plugin/blob/master/src/main/java/org/jenkinsci/plugins/builduser/utils/UsernameUtils.java :)
kalpesh soni
kohsuke, why is this not part of jenkins core? :)
Martin Wiklundh
I'm trying to use this with build-name-setter plugin but I can't get it to work. Am I missing something obvious?
Gavriil Konovalenko
Hi Martin, what's going wrong? Please provide an example of what you're doing.
Martin Wiklundh
It looks like the build-name-setter plugin executes before the build user vars. When the build-name-setter tries to set the build name with BUILD_USER_ID there is no variable set and it fails. Is there some way to change the evaluation order in the Build Environment part of the job config?
We have lots of jobs started by lots of users, I'll be the local hero if I can get this more visible.
Sunil Deshpande
Does this plug-in really work?
I tried with my Jenkins setup 1.471; Did not find it working.
Gavriil Konovalenko
Hi Sunil, yes it works. What's your issue? What is going wrong? Haven't you forgotten to enable "Set jenkins user build variables" checkbox?
Sunil Deshpande
I do have the checkbox checked. I am trying to do exactly same as shown in the Usage Example here on this page. Jenkins is on Windows hence I tried - Execute windows batch command in Post build Step. I tried following variations -
echo "Full name: $BUILD_USER"
echo "Full name: " $BUILD_USER
echo "Full name: " ${BUILD_USER}
echo "Full name: ${BUILD_USER}"
For all these output was either - Full name: $BUILD_USER
OR Full name: ${BUILD_USER}
Gavriil Konovalenko
Hi Sunil, in case of windows batch you should use %BUILD_USER% instead of $BUILD_USER.
echo "Full name: %BUILD_USER%"
echo "Full name: %BUILD_USER_FIRST_NAME%"
echo "Full name: %BUILD_USER_LAST_NAME%"
echo "Full name: %BUILD_USER_ID%"
Sunil Deshpande
Thanks for that reply.
Here's what I found:
I wish there was a way to distinguish if the build is triggered by Timer Or SCM Change.
Larry Cai
This is what I want as well !
Dustin Masterson
Have you looked into the
BUILD_CAUSE
and/orBUILD_CAUSE_TIMERTRIGGER
environment variables?John McGowan
Hi,
Having a bit of trouble with passing BUILD_USER_ID from one project (dev build) to a downstream project (to test it). I've "Set jenkins user build variables" set and when I do a build I can see them all if I do an env in the build shell step:
So to pass them to the downstream I've "Trigger parameterized build on other projects" set and a few predefined key/value pairs. The thing is only UPSTREAM_BUILD_NUMBER and UPSTREAM_BUILD_URL are actually worked out, and the others are just as is.
In the downstream project console log when env is called from the shell script (and visible when the downstream project is in the queue by hovering over the job) they aren't passed through:
what am I doing wrong. Do I need to use envinject plugin? I just want to pass the userid so I can take that and mail the person that started the overall job.
Thanks in advance,
John
EDIT:
I switched to using JobExporter from the main job, set it to artifact the properties file and still pass the build number in a parameterized build of the downstream job. Then in it wget the correct file to its workspace and grab what I need.
Magnus Jacobsson
This plugin doesn't work for matrix jobs. I'd like to file a bug i JIRA, but the build-user-vars-plugin component doesn't exist. Can someone create it?
rose red
Hey folks,
Trying to download build-user-vars-plugin but can’t find it in available plugins in jenkins. Is it named something different? or any tip to download it.
Thanks
rose red
Hey folks,
Trying to download build-user-vars-plugin but can’t find it in available plugins in jenkins. Is it named something different? or any tip to download it.
Thanks
T. David Wong
I was able to install it via Jenkins web UI. From "Manage Jenkins" >> "Manage Plugins" >> choose "Available" >> type "user build" in the filter field". The plug-in is actually showing as Jenkins user build vars plugin after installed.
Senthil Nathan
This plugin is not working on matrix config projects. It would be good if this plugin supports that too.
Even after enabling "Set jenkins user build variables" and trying to print in the execute shell command using "export BUILD_USER=$BUILD_USER"05:16:35 $ /bin/sh -xe /tmp/hudson1996225104865305122.sh
05:16:35 + export BUILD_USER=
05:16:35 + BUILD_USER=
T. David Wong
This is really a great plug-in, especially for Jenkins newbie like me.
I do have a feature request --- Is it possible to enhance this plug-in to retrieve the BUILD_USER_EMAIL value?
Vishal Rekala
Will this work in Groovy?
I would like to use in Execute Groovy Script????
Shannon Kerr
Is it BUILD_USER or BUILD_USER_NAME or both?
Gavriil Konovalenko
Check plugin description for list of supported variables:
https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin#BuildUserVarsPlugin-Variablesprovided
Remember about variables expansion, i.e. in linux it will be $BUILD_USER but in windows - %BUILD_USER%
Masthan Vali
Hello Team,
I have a scenario, like we have 100+ jobs in our Jenkins. The requirement is, the editable email notification plugin should send an mail with the detials of the Build Requestor.
With Build user vars plugin we are able to acheive this , by selecting the option " set jenkins user variable" in Configure Jenkins Job page and including $Build_User in email content.
As we have 100+ jobs is there any option to set this option at Manage Jenkins level.
I have declared the $BUILD_USER in the Default Content at Manage Jenkins level. But we are getting the Build Requestor details only for the Jobs for which the option " set user jenkins variable" option is selected.
Is there any option by which we can acheive this by doing something at Manage Jenkins level instead of configuring each and every jobAs we have 100+ jobs.
Thanks for your help in advance.
Regards,
Masthan Vali
Gavriil Konovalenko
Hi Masthan,
very good question, worth raising a feature request. This needs s code update and won't be as fast as you would like to have it.
there also were questions like "why this is not part of Jenkins". Probably this will become default Jenkin's feature at some point of time :)
as workaround, I would suggest you find jobs folder on the file system and update all jobs' configs by adding tag enabling "set user jenkins variable" option.
Masthan Vali
Hello Gavrill konovalenko,
Thankyou very much for your quick respose and work around.
Jenkins users would be excited to see this feature as default one.
Wishing Success to the team.
Regards,
Masthan Vali
Masthan Vali
Hi Gavriil,
I have followed the work around provided by you. I have executed below line where I could do modification to the config.xml and the 'set user jenkins variable" got enabled.
perl -i -pe 's/\<buildWrappers\/\>/\<buildWrappers\>\n\t\<org.jenkinsci.plugins.builduser.BuildUser plugin="build-user-vars-plugin@1.5"\/\>\n\t\<\/buildWrappers\>/g' ./config.xml
But we need to do this to each and every job's config.xml. Could you please help me with a script which executes the above modification in each and every job's config.xml under /jenkins/jobs//config.xml
Gavriil Konovalenko
Hi Masthan,
here is something what will help you do replacement in multiple files: http://stackoverflow.com/questions/19995368/perl-find-and-replace-specific-string-in-mulitiple-text-file
Have a fun :)
Stewart Evans
Is anyone using this plugin in conjunction with the Environment Dashboard plugin ( https://wiki.jenkins-ci.org/display/JENKINS/Environment+dashboard+plugin )? I'm trying to use ${BUILD_USER_ID} as my build number for dashboard display but it doesn't get expanded (the dashboard shows literally ${BUILD_USER_ID}). However in my shell build step, "echo $BUILD_USER_ID" works as expected.
Sreekanth C S
Hello Stewart,
I am also facing almost the same issue, "$BUILD_USER_ID" is what it prints and not the value.
Rolling back to version 1.4 is working fine.
Sven Keller
Hi,
I want to use the Variables from this plugin in a groovy post-build. since it is not explicitely mentioned, can somebody confirm, that using the variables other than in a regular build step is not supported?
If so, I really would like to vote for this feature in future releases.
All recommendations I've found so far are workarounds in best case but in fact they're rather ugly tries to overcome this (potential) limitation.
I'd really appreciate if there is a smart solution by extending this plugin.
But perhaps I'm totally wrong and just not able to use it correctly? Then, I'm happy to learn how to do so.
Thanks alot
demogorgonx -
I can't get the Build User Vars Plugin to work with the Pipeline Plugin (https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin).
I noticed that checking the "Set jenkins user build variables" box adds the following line to the config.xml of my Jenkins job:
So I tried the following in my Pipeline script:
But it prints out null.
James Withers
http://stackoverflow.com/questions/35902664/get-user-name-from-jenkins-workflow-pipeline-plugin#35902865
Jordan Juel
I am not able to get this plugin to work. I am on Windows. I have selected the checkbox and added in the line:
Then in my log it just prints out:
And idea? I can give more information if needed. Thanks!
demogorgonx -
You could double check that you're running a "Windows batch command" as opposed to an "Execute shell" command. The % signs for varaibles would only work in the former.
Jordan Juel
Well it appears that we are using PowerShell. However, when I change it to $BUILD_USER I get a blank or null like it isn't being set. So I guess I am having a similar issue to yours above mine here.
Eitan Sch
When using AD I'd expect the $BUILD_USER_EMAIL (for instance) to be populated from the AD and not manually set. Any solutions?
John Chen
Note that on the Jenkins plugin page I have to search for "
" to install it
Roger Groom
I'm not having any luck getting this plugin to work. Jenkins 2.119 on Ubuntu.
My build job has a bash script containing the following however each of BUILD_USER_FIRST_NAME and BUILD_USER_LAST_NAME are always returned empty. The user logged-in who is starting the build does have a first name and last name specified.
USERNAME="${BUILD_USER_FIRST_NAME} ${BUILD_USER_LAST_NAME}"
Justin Hair
Make sure to enable the "Set jenkins user build variables" in your build environment for the Jenkins job you are working on.
Joe Bob
I'm not able to get this to work either, I have the "Set jenkins user build variables" checked in my job and the variable just returns empty. I am using a Powershell build step, other Jenkins env vars work such as $ENV:JOB_NAME work normally, but none of the ones from this plugin work properly.
Joe Bob
I had to use $ENV:BUILD_USER for this to work, at least in my Powershell build step.
C Veeh
Doesn't work with Multi-branch pipelines (where you have a Jenkinsfile under source control).
It looks like it's stopped by Sandbox security.
It also doesn't work in a trusted global library.
CORRECTION: It does work if you upgrade your pipeline plugin collection to the latest ones.