Last active
February 22, 2023 15:17
-
-
Save handstandsam/4166cba4fc6778b323983abb96d83c08 to your computer and use it in GitHub Desktop.
Bash Script - Get Jenkins Job Status over API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BUILD_NUMBER=""; | |
STATUS="None"; | |
COMPLETE="false"; | |
function isJenkinsJobComplete() { | |
API_RESPONSE=`curl ${1}`; | |
STATUS=`echo "${API_RESPONSE}" | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["result"]'`; | |
BUILD_NUMBER=`echo "${API_RESPONSE}" | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["id"]'`; | |
if [ ${STATUS} != "None" ]; then | |
COMPLETE='true'; | |
else | |
COMPLETE='false'; | |
fi | |
} | |
isJenkinsJobComplete "https://myhost/myjob/lastBuild/api/json" | |
echo "Build #${BUILD_NUMBER} is complete: ${COMPLETE}, status is: ${STATUS}"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment