Skip to content

Instantly share code, notes, and snippets.

@matsskoglund
Created June 21, 2018 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsskoglund/c0a5e01151a2fc7d96e91b03ecdad2eb to your computer and use it in GitHub Desktop.
Save matsskoglund/c0a5e01151a2fc7d96e91b03ecdad2eb to your computer and use it in GitHub Desktop.
Remove all Gitlab runners for a user and group
#!/bin/bash
PAMTOKEN=YoUrPaMtOkEn
USERNAME=username
GROUPNAME=groupname
echo Disable all runners for a user
curl -s --request GET --header "PRIVATE-TOKEN: $PAMTOKEN" "https://gitlab.com/api/v4/users/$USERNAME/projects"|jq '.[].id'|while read -r line1; do command curl -s --header "PRIVATE-TOKEN: $PAMTOKEN" "https://gitlab.com/api/v4/projects/$line1/runners"|jq '.[].id'|while read -r line; do command curl --request DELETE --header "PRIVATE-TOKEN: $PAMTOKEN" "https://gitlab.com/api/v4/projects/$line1/runners/$line"; done;done
echo Disable all runners for a group
curl -s --request GET --header "PRIVATE-TOKEN: $PAMTOKEN" "https://gitlab.com/api/v4/groups/$GROUPNAME/projects"|jq '.[].id'|while read -r line1; do command curl -s --header "PRIVATE-TOKEN: $PAMTOKEN" "https://gitlab.com/api/v4/projects/$line1/runners"|jq '.[].id'|while read -r line; do command curl --request DELETE --header "PRIVATE-TOKEN: $PAMTOKEN" "https://gitlab.com/api/v4/projects/$line1/runners/$line"; done;done
echo Delete all runners that are not on several projects
curl -s --header "PRIVATE-TOKEN: $PAMTOKEN" "https://gitlab.com/api/v4/runners"|jq '.[].id'|while read -r line; do command curl --request DELETE --header "PRIVATE-TOKEN: $PAMTOKEN" "https://gitlab.com/api/v4/runners/$line"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment