Jenkins - Get last completed build status

Solution 1:

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

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

Solution 2:

To get the last successful build number:

curl --user <userName:password> https://<url>/job/<job-Name>/api/xml?xpath=/*/lastSuccessfulBuild/number