Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In trying to make doing the right thing easy, I'm looking for and making command line tools for our developers.

I'm hoping to find a way that I can check the jenkins build status without switching to the browser.

If I need to I'll make a script using the json api but was wondering if there's already something like this built in.

Anyone know?

share|improve this question
up vote 18 down vote accepted

I couldn't find a built in tool so I made one:

# author: ajs
# license: bsd
# copyright: re2

import json 
import sys
import urllib2

jenkinsUrl = ""

if len( sys.argv ) > 1 :
    jobName = sys.argv[1]
else :

    jenkinsStream   = urllib2.urlopen( jenkinsUrl + jobName + "/lastBuild/api/json" )
except urllib2.HTTPError, e:
    print "URL Error: " + str(e.code) 
    print "      (job name [" + jobName + "] probably wrong)"

    buildStatusJson = json.load( jenkinsStream )
    print "Failed to parse json"

if buildStatusJson.has_key( "result" ):      
    print "[" + jobName + "] build status: " + buildStatusJson["result"]
    if buildStatusJson["result"] != "SUCCESS" :

share|improve this answer

Check to see if a build is running or not

I tried the Python script in the answer to this question, but couldn't get it to work. I don't know Python, and didn't want to invest any time in debugging, but was able to read enough of the script to gain inspiration from it.

All I need to do is check to see if a build is running or not. To do that I used curl and grep, like this:

curl http://myjenkins/job/myjob/lastBuild/api/json | grep --color result\":null

  • If a build is in progress, a grep for result\":null will return 0.
  • If a build is finished, a grep for result\":null will return 1.

Not especially elegant, but it works well enough for my needs.

For example, I have a Bash script that starts a build, then waits for it to finish:



# Start the build
curl $JOB_URL/build?delay=0sec

# Poll every thirty seconds until the build is finished
while [ $GREP_RETURN_CODE -eq 0 ]
    sleep 30
    # Grep will return 0 while the build is running:
    curl --silent $JOB_STATUS_URL | grep result\":null > /dev/null

echo Build finished

Thanks for the inspiration, Catskul!

share|improve this answer
I went and checked my current implementation which is working, and it's a bit different than the version I put in the answer because of some password requirements. Do you know why it wasn't working for you? – Catskul Aug 28 '12 at 17:01
The Python script works great if a job has already finished, but if a job is running, the Python script fails: TypeError: cannot concatenate 'str' and 'NoneType' objects. I don't know Python, so I switched to using shell and +1ed your answer for the inspiration. Thanks! – Steve HHH Aug 28 '12 at 22:07

A former colleague of mine wrote this: which has a whole bunch of convenience features and API type stuff around working with a jenkins instance from Python..

share|improve this answer

Fortunately, there is a jenkins-cli that you can use to get some information from jenkins. Unfortunately, you can't retrieve the status of a build using the CLI--which means your solution of using the JSON API is not only correct--its the only programatic way of doing so.

Also, while it looks like get-job might do what you want, it doesn't actually return the result--it only returns the job configuration.

share|improve this answer

I know it's been a long time since this question was asked, but I think I found an easier way.

If I understood correctly, you want to check the result of the build - if it was a success or a failure, in other words.

Jenkins CLI's "build" command changes the exit code depending on the result of the build, as long as you use the -s or -f option at the end.

For example,

java -jar jenkins-cli.jar -s <url of Jenkins instance> build <project> -s


java -jar jenkins-cli.jar -s <url of Jenkins instance> build <project> -f

Notice that the option goes at the end; it's not the first -s, which is used to define the url of the jenkins instance.

And then, to get the result, you can use $?

echo $?

If the result is 0, it was a success. If it's something other than 0, it was a failure.

Reference: I can't find a public Jenkins instance that gives access to this page, but it can be found in your local Jenkins instance: http://<url of Jenkins Instance>/cli/command/build. It also explains the difference between -s and -f.

share|improve this answer

Another python solution:

from jenkinsapi.jenkins import Jenkins

jenkins_url = 'http://<server url>/'
server = Jenkins(jenkins_url, username = 'myUser', password = myPass)

job_instance = server.get_job('the job name')
running = job_instance.is_queued_or_running()
if not running:
   print latestBuild.get_status()
share|improve this answer

You can use the symbolic descriptor lastBuild:


The result element in the response contains a string describing the outcome of the build.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.