I would like to get the username who triggered the Jenkins job in the Post build task. At first i thought the Build User Vars Plugin could work but than i realize those variables are only available in the Build process but not the post build action.
Luckily, i found a blog post written by Donald Simpson which help me to solve the problem.
So for each Jenkins build, there is an xml which summarizes the details about the build which could be access thru the following url.
In order words, just go to a specific build number in the history list and add api/xml at the end.
To get the username, we can make use of the curl command is to access this xml file.
curl ${BUILD_URL}api/xml --silent | xml_grep --text_only userName
So here is a Post build task script to print the username to the console output.
THE_USER="$(curl ${BUILD_URL}api/xml --silent | xml_grep --text_only userName)" echo "-------------" echo $THE_USER echo "-------------"
Done =)
Filed under: Continuous Integration, Jenkins Tagged: Donald Simpson, Jenkins, Shell Script Image may be NSFW.
Clik here to view.

Clik here to view.
