2

I want to get the status of a job in jenkins through java.

Is there any API which I can refer?

ajc
  • 1,685
  • 14
  • 34
  • possible duplicate of [how to get the list of jobs in Jenkins using java?](http://stackoverflow.com/questions/21086380/how-to-get-the-list-of-jobs-in-jenkins-using-java) – Dave Bacher Mar 23 '15 at 21:00
  • Dave, I actually want the status of one of the jenkins job. In other words, Whether the job is currently running or executed. If so, what was the status and console log. I think it is different from the suggestion. Please let me know if I am right? – ajc Mar 23 '15 at 21:41
  • ajc, there are several other very similar questions on this site that should give you the pointers you need to find a solution (e.g. http://stackoverflow.com/q/12944403/172599, http://stackoverflow.com/q/14843874/172599). – Dave Bacher Mar 24 '15 at 05:23

2 Answers2

2

Yah, right here https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API is the API reference

Slav
  • 27,057
  • 11
  • 80
  • 104
  • I did land on this link, but there are no endpoints for the api. All that is mentioned is - "That is, there is no single entry point for all features, and instead they are available under the ".../api/" URL where "..." portion is the data that it acts on." – ajc Mar 23 '15 at 21:38
  • Because it depends on your version and plugins. So, do what it says, point to your jenkins URL, some job, and then just put "/api/" at the end of the URL and you will see all the available end points – Slav Mar 24 '15 at 13:14
1

You can get if the build is successful or failure using the below REST api link:

http://myJenkinsMachine/job/someJob/api/xml You will get the below xml with color of the build (blue or any other color):

<freeStyleProject>

<description/>

<displayName>someJob</displayName>

<name>someJob</name>

<url>http://myJenkins/job/someJob/</url>

**<buildable>true</buildable>**

<build>

<number>4</number>

<url>http://myJenkins/job/someJob/4/</url>

</build>

<build>

<number>3</number>

<url>http://myJenkins/job/someJob/3/</url>

</build>

<build>

<number>2</number>

<url>http://myJenkins/job/someJob/2/</url>

</build>

<build>

<number>1</number>

<url>http://myJenkins/job/someJob/1/</url>

</build>

<color>blue</color>

<firstBuild>

<number>1</number>

<url>http://myJenkins/job/someJob/1/</url>

</firstBuild>

<healthReport>

<description>Build stability: No recent builds failed.</description>

<iconUrl>health-80plus.png</iconUrl>

<score>100</score>

</healthReport>

<inQueue>false</inQueue>

<keepDependencies>false</keepDependencies>

<lastBuild>

<number>4</number>

<url>http://myJenkins/job/someJob/4/</url>

</lastBuild>

<lastCompletedBuild>

<number>4</number>

<url>http://myJenkins/job/someJob/4/</url>

</lastCompletedBuild>

<lastStableBuild>

<number>4</number>

<url>http://myJenkins/job/someJob/4/</url>

</lastStableBuild>

<lastSuccessfulBuild>

<number>4</number>

<url>http://myJenkins/job/someJob/4/</url>

</lastSuccessfulBuild>

<lastUnsuccessfulBuild>

<number>3</number>

<url>http://myJenkins/job/someJob/3/</url>

</lastUnsuccessfulBuild>

<nextBuildNumber>5</nextBuildNumber>

<concurrentBuild>false</concurrentBuild>

<scm/>

</freeStyleProject>

OR

http://myJenkinsMachine/job/someJob/api/xml?depth=4 - to get more details upto level 4 - whether building or not

<freeStyleProject>
<description/>
<displayName>somejob</displayName>
<name>somejob</name>
<url>http://myJenkins/job/somejob/</url>
<allBuild>
<action>
<cause>
<shortDescription>Started by user ancd</shortDescription><userId>ancd</userId><userName>ancd</userName></cause></action><action/>
**<building>false</building>**
<duration>236018</duration>
Work
  • 73
  • 1
  • 9