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?
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.
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.
Try http://$host/job/$jobname/lastSuccessfulBuild/api/json
Jenkins (and Hudson) expose multiple different builds, such as lastBuild, lastStableBuild, lastSuccessfulBuild, lastFailedBuild, lastUnstableBuild, lastUnsuccessfulBuild, lastCompletedBuild.
To get the last successful build number:
curl --user <userName:password> https://<url>/job/<job-Name>/api/xml?xpath=/*/lastSuccessfulBuild/number
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With