Skip to content

Instantly share code, notes, and snippets.

@ufukty
Last active June 25, 2026 13:37
Show Gist options
  • Select an option

  • Save ufukty/2f4f4215e8d5ad3c34e8caa0febcb933 to your computer and use it in GitHub Desktop.

Select an option

Save ufukty/2f4f4215e8d5ad3c34e8caa0febcb933 to your computer and use it in GitHub Desktop.
Delete Cloudflare Pages deployments of a project
#!/usr/bin/env bash
: "${ACCOUNT_ID:?}"
: "${API_TOKEN:?}"
: "${PROJECT_NAME:?}"
set -eu
API="https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/pages/projects/${PROJECT_NAME}"
AUTH="Authorization: Bearer ${API_TOKEN}"
active() {
curl -fsS -H "$AUTH" "$API" | jq -r '.result.latest_deployment.id'
}
deployments() {
curl -fsS -H "$AUTH" "$API/deployments"
}
filter-remaining() {
jq -r '.result_info.total_count'
}
filter-ids() {
jq -r '.result[].id'
}
delete-deployment() {
curl -fsS -H "$AUTH" -X DELETE "$API/deployments/${1:?}?force=true"
}
ACTIVE_DEPLOYMENT_ID="$(active)"
while true; do
NEXT_PAGE="$(deployments)"
echo "remaining: $(echo "$NEXT_PAGE" | filter-remaining)"
IDS="$(echo "$NEXT_PAGE" | filter-ids)"
if test "$IDS" == "$ACTIVE_DEPLOYMENT_ID"; then
echo "only the active deployment left"
exit 0
fi
echo "$IDS" | while read -r DEPLOYMENT_ID; do
if test "$DEPLOYMENT_ID" == "$ACTIVE_DEPLOYMENT_ID"; then
echo "passing the active deployment $DEPLOYMENT_ID..."
continue
fi
echo "deleting $DEPLOYMENT_ID..."
delete-deployment "$DEPLOYMENT_ID" >/dev/null
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment