Skip to content

Instantly share code, notes, and snippets.

@jossemarGT
Created September 26, 2016 16:52
Show Gist options
  • Select an option

  • Save jossemarGT/a0646c147f200e0f536c3cc80cda28ea to your computer and use it in GitHub Desktop.

Select an option

Save jossemarGT/a0646c147f200e0f536c3cc80cda28ea to your computer and use it in GitHub Desktop.
Drains jenkins build queue using curl and jq
#!/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