Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created October 2, 2022 16:15
Show Gist options
  • Save KyMidd/a45fb82e09e503de1849a3779f355456 to your computer and use it in GitHub Desktop.
Save KyMidd/a45fb82e09e503de1849a3779f355456 to your computer and use it in GitHub Desktop.
while [ i = i ]; do
# Check job status
echo "Query Build Job Status"
BUILDING=$(curl -s -X GET -u "$userName:$api_token" "${urlOfJenkinsServer}/job/${jenkinsJobName}/api/json?depth=10&tree=builds\[queueId,id,building,result,url\]&pretty=true" | jq -r ".builds[] | select(.id==\"$JOBID\") | .building")
JOBSTATUS=$(curl -s -X GET -u "$userName:$api_token" "${urlOfJenkinsServer}/job/${jenkinsJobName}/api/json?depth=10&tree=builds\[queueId,id,building,result,url\]&pretty=true" | jq -r ".builds[] | select(.id==\"$JOBID\") | .result")
if [ "$JOBSTATUS" == "null" ]; then
# Job is still building
echo "Job is still building: ${BUILDING}"
else
# If JOBSTATUS populated, it has finished. Break and exit watch loop
break
fi
# Wait pollTime seconds
echo "Jenkins still working hard, sleeping for ${pollTime} seconds"
echo "--------------------------------------"
sleep $pollTime
currentTimeSeconds=$(date +%s)
if [[ "$currentTimeSeconds" > "$finishTimeInSeconds" ]]; then
echo "Timeout value reached. Exiting with error due to timeout"
echo "--------------------------------------"
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment