How to delete deployments? #85000
-
Select Topic AreaQuestion BodyCould someone help me with this question? I have a repository where there is a lot of implementation history. I would like to clean it. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
It appears you can use GitHub CLI for that too: gh api \
--method DELETE \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/OWNER/REPO/deployments/DEPLOYMENT_ID Or curl: curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/deployments/DEPLOYMENT_ID This may help: https://docs.github.com/en/rest/deployments/deployments |
Beta Was this translation helpful? Give feedback.
-
In case others come across this like me, I wanted to clear all the deployments for a repo but deleting the env and recreating it with the same name kept them all. The below will fetch 100 deployments at a time and then delete them with the NOTE: this will do it for each environment curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/deployments\?per_page\=100 | jq -r '.[].id' | xargs -P 0 -I {} curl -L \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/deployments/\{\} |
Beta Was this translation helpful? Give feedback.
-
I used this script to delete all deployments for an environment
|
Beta Was this translation helpful? Give feedback.
-
I recently ran into something similar and learned that I had to mark deployments as inactive before deleting them. This script marks all deployments as inactive, and deletes all deployments, 100 at a time. REPO="OWNER_NAME/REPO_NAME"
for ID in $(gh api --method GET "/repos/$REPO/deployments?per_page=100" | jq -r ".[] | .id")
do
gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" --method POST /repos/$REPO/deployments/$ID/statuses -f "state=inactive"
gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" --method DELETE /repos/$REPO/deployments/$ID
done |
Beta Was this translation helpful? Give feedback.
It appears you can use GitHub CLI for that too:
Or curl:
This may help: https://docs.github.com/en/rest/deployments/deployments