Created
September 26, 2016 16:52
-
-
Save jossemarGT/a0646c147f200e0f536c3cc80cda28ea to your computer and use it in GitHub Desktop.
Drains jenkins build queue using curl and jq
This file contains hidden or 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 | |
| JENKINS_URL=$1 | |
| HINT=${2-master} | |
| USER=${3-jenkins} | |
| JENKINS_TOKEN=$4 | |
| REMINDER=`mktemp /tmp/${HINT}.XXXXX` | |
| echo "ID's will be printed on ${REMINDER}" | |
| curl ${JENKINS_URL}/queue/api/json --user $USER:$JENKINS_TOKEN | \ | |
| jq '.items[] | " \(.id) \(.task.name)"' | \ | |
| grep $HINT | \ | |
| cut -f2 -d' ' > $REMINDER | |
| while read JID; do | |
| echo "Cancel $JID" | |
| curl -X POST ${JENKINS_URL}/queue/cancelItem\?id\=$JID --user $USER:$JENKINS_TOKEN | |
| done < $REMINDER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment