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.
- The plugin is very simple to use. Go the job where we want to access the USER details variable.
- Click on the option as shown in the image. Which will allow us to use the variable.
- 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: