Quality Gate Failure in SonarQube does not fail the build in Teamcity

Nikit Swaraj picture Nikit Swaraj · Sep 27, 2018 · Viewed 9.4k times · Source

I set up a Build project in TeamCity and integrated Sonarqube with it. The project is getting build and even publish the report successfully in SonarQube console. But when the quality gate fails, it's not breaking the build. I searched and read about the build breaker, but its already supported with Sonarqube plugin of TeamCity as this document https://confluence.jetbrains.com/display/TW/SonarQube+Integration

Am I missing something to configure/or any gotcha? I tried to search a lot but didn't find any sort of proper documentation or lead on that.

Answer

Nikit Swaraj picture Nikit Swaraj · Oct 1, 2018

Yeah I have to write a custom script using exit status to break the build. I used API to analyse the status of QG.

PROJECTKEY="%teamcity.project.id%"
QGSTATUS=`curl -s -u  SONAR_TOKEN: http://SONAR_URL:9000/api/qualitygates/project_status?projectKey=$PROJECTKEY | jq '.projectStatus.status' | tr -d '"'`
if [ "$QGSTATUS" = "OK" ]
then
exit 0
elif [ "$QGSTATUS" = "ERROR" ]
then
exit 1
fi