Skip to content

Instantly share code, notes, and snippets.

@mcncl
Created March 27, 2024 00:13
Show Gist options
  • Save mcncl/de282b9c39669df683715be3ffb351ca to your computer and use it in GitHub Desktop.
Save mcncl/de282b9c39669df683715be3ffb351ca to your computer and use it in GitHub Desktop.
Cancel all running Buildkite builds
#!/bin/bash
# Make API call to retrieve initial objects and extract URLs
urls=($(http -I -A bearer --auth "$TOKEN" GET "https://api.buildkite.com/v2/organizations/ORG/builds?state=running" | jq -r '.[] | .url'))
# Loop through URLs, append /cancel, and make API calls
for url in "${urls[@]}"; do
cancel_url="${url}/cancel"
echo "Making API call to cancel: $cancel_url"
# Make API call here (curl example provided)
# Replace 'curl' with your API call command
curl -s -H "Authorization: Bearer $TOKEN" -X PUT "$cancel_url" >> /dev/null
echo "Cancelled $cancel_url :white_check_mark:"
done
## state=running can bu adjusted to be any state, such as state=scheduled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment