DVG
DVG

Reputation: 17480

Jenkins - Get last completed build status

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

Answers (3)

Sivan Becker
Sivan Becker

Reputation: 31

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()

Upvotes: 1

Kiruthika kanagarajan
Kiruthika kanagarajan

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

coffeebreaks
coffeebreaks

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

Related Questions