Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check SonarQube's Quality Gate from TeamCity's build step #sonarqube #teamcity #qualitygate #quality #gate #ci #continousintegration

Realiza un curl, recupera la respuesta, busca si aparece la palabra ERROR en la response, cuenta cuantas veces ocurre y si ocurre envía un exit 2 para que falle. Si 0 es que response no devolvió ERROR en ningún sitio.

echo "============> SonarQube's Quality Gate <============" &&
#Initializing two variables 
ERR_COUNT=`curl http://127.0.0.1:9000/api/qualitygates/project_status?projectKey=MyAwesomeProjectKey -L | grep -Eo 'ERROR' | wc -l`

#Check whether they are equal 
if [ $ERR_COUNT -eq 0 ] 
then 
    echo "QUALITY GATE PASSED!"
    echo $ERR_COUNT
fi

if [ $ERR_COUNT != 0 ] 
then 
    echo "QUALITY GATE NOT PASSED!"
    echo $ERR_COUNT
    exit 2
fi
@Netznarkose
Copy link

Netznarkose commented Aug 12, 2021

Thanks for sharing! I just implemented a similar thing in our pipeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment