Forked from matheusneder/sonarqube-delete-long-branches.sh
Created
March 14, 2023 13:22
-
-
Save vdupain/8e318fe7794fce5da1b58ea454bcef48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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