Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins - Get last completed build status

Tags:

jenkins

api

I know I can call localhost/job/RSpec/lastBuild/api/json to get the status of the lastest Jenkins build. However, since our build runs very long (a couple hours), I'm really more interested in the last complete build status than the run that is running at this exact moment.

Is there an api end point for the last fully run build? Or should I instead pull the full list of builds and select the next-to-last one from there?

like image 755
DVG Avatar asked Aug 14 '13 17:08

DVG


People also ask

How do I find the latest build in Jenkins?

If the plugin doesn't appear in your Jenkins Update Centre, visit Manage Plugins / Advanced and click the "Check now" button to make Jenkins retrieve the latest update-center.

How do I get Jenkins job status in Python?

Querying Jenkins The first step that you will want to accomplish is getting the jobs by their status. The standard statuses that you will find in Jenkins are SUCCESS, UNSTABLE or ABORTED. Here you create an instance of Jenkins and assign it to server. Then you use get_view_by_url() to get the specified view name.


2 Answers

Try http://$host/job/$jobname/lastSuccessfulBuild/api/json

Jenkins (and Hudson) expose multiple different builds, such as lastBuild, lastStableBuild, lastSuccessfulBuild, lastFailedBuild, lastUnstableBuild, lastUnsuccessfulBuild, lastCompletedBuild.

like image 197
coffeebreaks Avatar answered Sep 27 '22 21:09

coffeebreaks


To get the last successful build number:

curl --user <userName:password> https://<url>/job/<job-Name>/api/xml?xpath=/*/lastSuccessfulBuild/number 
like image 28
Kiruthika kanagarajan Avatar answered Sep 27 '22 20:09

Kiruthika kanagarajan