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 Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals