Skip to content

Instantly share code, notes, and snippets.

@kamawanu
Last active August 13, 2017 14:19
Show Gist options
  • Save kamawanu/20386f1c3ffbbf30030879e29dbb43bf to your computer and use it in GitHub Desktop.
Save kamawanu/20386f1c3ffbbf30030879e29dbb43bf to your computer and use it in GitHub Desktop.
#!/bin/bash
#set +x
set +x -e
which jq || {
echo jq not found ; exit 9
}
which curl || {
echo curl not found ; exit 9
}
selfabort () {
echo self $BUILD_URL terminate.
curl -X POST -qs $BUILD_URL/stop
exit 9
}
NEXTBASE=$( curl -qs "${JOB_URL}api/json" | jq -c -r .downstreamProjects[0].url )
echo next $NEXTBASE found.
COUNT=0
while :
do
MUSTNULL=$( curl -qs ${NEXTBASE}api/json | jq -c -r .queueItem )
if [ "x$MUSTNULL" \!= "xnull" ]
then
echo $NEXTBASE has queue
selfabort
exit 1
fi
NEWESTJOB=$( curl -qs ${NEXTBASE}api/json | jq -c -r .lastBuild.url )
IS_BUILDING=$( curl -qs $NEWESTJOB/api/json | jq -c -r ".building" )
if [ $IS_BUILDING == true ]
then
echo next $NEXTBASE is building on $NEWESTJOB
selfabort
exit 1
fi
COUNT=$(( $COUNT + 1 ))
if [ $COUNT -gt 1 ]
then
break
fi
echo next $NEXTBASE is empty , but wait $COUNT
sleep 5
echo retry...
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment