Created
March 17, 2023 17:19
-
-
Save lpsm-dev/ee00c5c62fd988e07a1cfb0c39a7cd3c to your computer and use it in GitHub Desktop.
[DevOps] - Script to setup a quality gate in Sonarqube project
This file contains hidden or 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 | |
# Define variables | |
SONARQUBE_TOKEN="" | |
SONARQUBE_URL="" | |
QUALITY_GATE_NAME="" | |
PROJECT_KEY="" | |
# Get quality gate ID | |
QUALITY_GATE_ID=$(curl -s -u $SONARQUBE_TOKEN: -X GET "$SONARQUBE_URL/api/qualitygates/list" | jq -r '.qualitygates[] | select(.name=="'"$QUALITY_GATE_NAME"'") | .id') | |
# Set up quality gate for project | |
curl -s -u $SONARQUBE_TOKEN: -X POST "$SONARQUBE_URL/api/qualitygates/select?projectKey=$PROJECT_KEY&gateId=$QUALITY_GATE_ID" | |
# Output success message | |
echo "Quality gate '$QUALITY_GATE_NAME' has been set up for project '$PROJECT_KEY'." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment