Reputation: 17480
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?
Upvotes: 54
Views: 106314
Reputation: 31
JenkinsAPI is also a nice option. I'm mainly using python and so here is my version of things:
pip install jenkinsapi
from jenkinsapi.jenkins import Jenkins
server = Jenkins(<Jenkins server URL>)
job = server.get_job(<job name>)
last_successful_build_number = job.get_last_good_buildnumber()
Upvotes: 1
Reputation: 944
To get the last successful build number:
curl --user <userName:password> https://<url>/job/<job-Name>/api/xml?xpath=/*/lastSuccessfulBuild/number
Upvotes: 11
Reputation: 3817
Try http://$host/job/$jobname/lastSuccessfulBuild/api/json
Jenkins (and Hudson) expose multiple different builds, such as lastBuild, lastStableBuild, lastSuccessfulBuild, lastFailedBuild, lastUnstableBuild, lastUnsuccessfulBuild, lastCompletedBuild.
Upvotes: 123