Jenkins - Get last completed build status

JenkinsAPI is also a nice option. I'm mainly using python and so here is my version of things:

  1. pip install jenkinsapi
  2. python code: (in my case no special authentication to Jenkins is needed, otherwise i assume a token is needed)
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()

To get the last successful build number:

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

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

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

Tags:

Api

Jenkins