Skip to content

Instantly share code, notes, and snippets.

@handstandsam
Last active February 22, 2023 15:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save handstandsam/4166cba4fc6778b323983abb96d83c08 to your computer and use it in GitHub Desktop.
Save handstandsam/4166cba4fc6778b323983abb96d83c08 to your computer and use it in GitHub Desktop.
Bash Script - Get Jenkins Job Status over API
#!/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