Using JSON & Curl
[code]BUILD_STATUS=$(curl –user USER:TOKEN_VALUE –silent $BUILD_URLapi/json | jq -r ‘.result’)
echo $BUILD_STATUS[/code]
Using jenkins Plugins
Plugins Name – Conditional Build Step
For Implementations, Please check here.
https://stackoverflow.com/questions/11125598/getting-the-build-status-in-post-build-script
Using Python & Json
[code]</pre>
#!/usr/bin/python
#
# author: ajs
# license: bsd
# copyright: re2
import json
import sys
import urllib
import urllib2
jenkinsUrl = “https://jenkins.example.com/job/”
if len( sys.argv ) > 1 :
jobName = sys.argv[1]
jobNameURL = urllib.quote(jobName)
else :
sys.exit(1)
try:
jenkinsStream = urllib2.urlopen( jenkinsUrl + jobNameURL + “/lastBuild/api/json” )
except urllib2.HTTPError, e:
print “URL Error: ” + str(e.code)
print ” (job name [” + jobName + “] probably wrong)”
sys.exit(2)
try:
buildStatusJson = json.load( jenkinsStream )
except:
print “Failed to parse json”
sys.exit(3)
if buildStatusJson.has_key( “result” ):
print “[” + jobName + “] build status: ” + buildStatusJson[“result”]
if buildStatusJson[“result”] != “SUCCESS” :
exit(4)
else:
sys.exit(5)
sys.exit(0)
Reference –
<a href=”http://serverfault.com/questions/309848/how-can…49988bb53ee820fe202a”>serverfault.com/questions/309848/how-can…49988bb53ee820fe202a</a>
<pre>[/code]













I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND