by
0
8
9,725
25
Top 1% !
Popular
Famous
Pearl of Wisdom
Tagged
Easy-to-find
Specified
OpenSource
Popularity: 505th place

Published on:

Architecturex86_64
LanguagePython
LicenseMIT_X11

How to parse the JSON result of a jenkins job in python

This snippet shows how to get and parse the JSON format of the last execution of a Jenkins job.
You have to specify:

Jenkins_server - The Jenkins server name/IP address

http_port - The port used by Jenkins server

job_name - The job name
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/3400/How-to-parse-the-JSON-result-of-a-jenkin?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
import urllib2 import json jenkins_job_dir="http://<Jenkins_server>:<http_port>/view/All/job/<job_name>/lastBuild/api/json" def getBuildResult(): try: jenkinsStream = urllib2.urlopen(jenkins_job_dir) except urllib2.HTTPError, e: print "URL Error: " + str(e.code) return "FAILURE" try: buildStatusJson = json.load( jenkinsStream ) except: print "Failed to parse json" return "FAILURE" if buildStatusJson.has_key( "result" ): print "build status job " + buildStatusJson["result"] if buildStatusJson["result"] != "SUCCESS" : return "FAILURE" else: return "FAILURE" return "SUCCESS" print "loading" getBuildResult() print "Done"
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus