Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the BUILD_USER in Jenkins when job triggered by timer?

I wanted to show the user who triggered a Jenkins job in the post job email. This is possible by using the plugin Build User Vars Plugin and the env variable BUILD_USER. But this variable do not get initialized when the job is triggered by a scheduler.

How can we achieve this? I know we have a plugin called - EnvInject Plugin, and that can be used...

But I just want to know how we can use this and achieve the solution...

like image 694
Musaffir Lp Avatar asked Mar 24 '16 06:03

Musaffir Lp


People also ask

How do you know who triggered Jenkins job?

I wanted to show the user who triggered a Jenkins job in the post job email. This is possible by using the plugin Build User Vars Plugin and the env variable BUILD_USER .

How do I get total build time in Jenkins?

You can use ${currentBuild. durationString} to get build duration.

Can Jenkins build be triggered automatically?

As soon as we will hit the URL in the browser, Jenkins will trigger the build automatically like in the below image.

What triggers to execute a Jenkins job?

Developers can follow these three steps to implement a remote Jenkins build trigger: Create a Jenkins build job and enable the Trigger builds remotely checkbox. Provide an authentication token; This can be any text string of your choice. Invoke the Jenkins build URL to remotely trigger the build job.


1 Answers

Build user vars plugin wasn't working for me so I did a quick-and-dirty hack:

BUILD_CAUSE_JSON=$(curl --silent ${BUILD_URL}/api/json | tr "{}" "\n" | grep "Started by") BUILD_USER_ID=$(echo $BUILD_CAUSE_JSON | tr "," "\n" | grep "userId" | awk -F\" '{print $4}') BUILD_USER_NAME=$(echo $BUILD_CAUSE_JSON | tr "," "\n" | grep "userName" | awk -F\" '{print $4}') 
like image 59
Kevin Brotcke Avatar answered Sep 30 '22 13:09

Kevin Brotcke