Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out how a build was triggered in Jenkins

Tags:

jenkins

hudson

I'm trying to update Jelly scripts in my Jenkins setup to email the reason for a build (the build trigger), but I can't find any documentation on this.

I know it should be available, as the build's page will show the information, but I want it to be displayed on the email being distributed.

Does anyone know if there is a var I can query, or a Jenkins API call I can call to get this?

like image 724
GKelly Avatar asked Aug 10 '11 09:08

GKelly


1 Answers

You can do it by calling this API.

More convinient, in env var setted before the build, you'll find BUILD_URL :

BUILD_URL=https://jenkins-server.tld/job/JOBNAME/BUILD_NUMBER

So you just need to append /api/json. You can also got it in xml :

<freeStyleBuild>
<action>
<cause>
<shortDescription>Started by user kenji</shortDescription>
<userName>kenji</userName>
</cause>
</action>
<action/>
<action/>
<action>
<failCount>0</failCount>
<skipCount>0</skipCount>
<totalCount>1</totalCount>
<urlName>testReport</urlName>
</action>
<building>false</building>
<duration>9772</duration>
<fullDisplayName>JOBNAME #4</fullDisplayName>
<id>2011-08-10_11-19-42</id>
<keepLog>false</keepLog>
<number>4</number>
<result>SUCCESS</result>
<timestamp>1312967982296</timestamp>
<url>https://jenkins-server.tld/job/JOBNAME/4/</url>
<builtOn>macboo</builtOn>
<changeSet>
<kind>svn</kind>
<revision>
<module>https://svn-server.tld/JOBNAME/trunk</module>
<revision>7</revision>
</revision>
</changeSet>
</freeStyleBuild>
like image 74
ıɾuǝʞ Avatar answered Nov 15 '22 11:11

ıɾuǝʞ