Skip to content

Instantly share code, notes, and snippets.

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 vdupain/8e318fe7794fce5da1b58ea454bcef48 to your computer and use it in GitHub Desktop.
Save vdupain/8e318fe7794fce5da1b58ea454bcef48 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
TOKEN=xxx
AUTH="Basic $(echo -n $TOKEN: | base64)"
SONARAPI="http://sonarqube/api"
for projKey in $(curl -s -X GET $SONARAPI/projects/search -H "Authorization: $AUTH" | \
jq -r '.components[].key')
do
projKey=$(echo $projKey | xargs)
echo "++++ PROJ: $projKey ++++"
for branchName in $(curl -s -X GET "$SONARAPI/project_branches/list?project=$projKey" \
-H "Authorization: $AUTH" | \
jq -r '.branches[] | select(.type == "LONG") | select (.isMain == false) | .name')
do
branchName=$(echo $branchName | xargs)
echo "---- DELETING BRANCH $branchName -----"
curl -s -X POST \
"$SONARAPI/project_branches/delete?project=$projKey&branch=$branchName" \
-H "Authorization: $AUTH"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment