Getting the user who started the jenkins job in variable

Normally, when we run our Jenkins job, we do get the log clearly showing who started the job in the top of the jenkins log console. But the problem with it is or we don’t have that user name stored in some variables. Jenkins provide some values in its environment variables like BUID_ID, EXECUTOR_ID, and some more but not the username or email associated with the build.

When might we need a user who started the job in variable:

Suppose we want to send the notification to the slack who executed the job. How can we do it. As there might be multiple users associated with the jobs. We need the variable containing the username that we can pass when calling the Slack api or passing with the message.

Jenkins has so many plugin to solve the problem. Particularly for this scenario I found the plugin named as user build vars. Yes install the plugin.

What to do after installing the user build vars plugin.

  1. The plugin is very simple to use. Go the job where we want to access the USER details variable.
  2. Click on the option as shown in the image. Which will allow us to use the variable.
    choose the option set jenkins users build
  3. Done, Now we can freely use the variable and access the user info like user name, email and many more

Variables provided by the set user variables can be seen by clicking on the info icons. These are the variables provided by the variable that we can use.

user build variables:

  • BUILD_USER — This provides the full name of user started build,
  • BUILD_USER_FIRST_NAME — Just first name of user started build,
  • BUILD_USER_LAST_NAME — Just last name of user started build,
  • BUILD_USER_ID — id of user started build.
  • BUILD_USER_EMAIL — The email of user started build.

Leave a Reply