Created
February 4, 2014 21:12
-
-
Save pianosnake/8812467 to your computer and use it in GitHub Desktop.
If you're using a Jenkins external monitoring job, you may want to fail the job if it's been too long since the last run. Put this script in a cron tab to check the time since the last successful build. If it's been longer than 2 minutes it will submit a failed job to Jenkins.
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 | |
# get the last sucessful build | |
XML=`curl http://localhost:8080/job/External-Monitoring/lastSuccessfulBuild/api/xml` | |
# extract the first 10 digits of the timestamp | |
TIMESTAMP=`echo $XML| sed -E 's/.*timestamp>(.*)\<\/timestamp.*/\1/' | cut -c1-10` | |
NOW=`date +"%s"` | |
DIFF=$((NOW-TIMESTAMP)) | |
if [[ $DIFF -gt 120 ]] | |
then | |
HEX=`echo "Haven't seen a sucessful job in over 2 minutes" | xxd -c 256 -p` | |
curl -X POST -d "<run><log encoding='hexBinary'>$HEX</log><result>1</result><duration>1</duration></run>" http://localhost:8080/job/External-Monitoring/postBuildResult | |
echo "It's been too long since last success: $DIFF" | |
else | |
echo "ok $DIFF" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment