Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 386
Nikit Swaraj Avatar asked Sep 27 '18 05:09

Nikit Swaraj


People also ask

What is quality gate failed in SonarQube?

Quality Gate represents the best way to implement the Clean as You Code concept by focusing on new code. ( Quality Gates | SonarQube Docs) By default, “New Code” is defined as code added or changed since the previous version. Meaning if you are refactoring your code, the refactored code is “New Code.”

How can I break the build based on the quality gate status?

Hi, We do not recommend failing your entire build. Instead, you can add a Branch Policy on your quality gate upon pull requests, and block them from merging if the Quality Gate fails.

What is the use of quality gates in SonarQube?

Quality Gates are the set of conditions a project must meet before it should be pushed to further environments. Quality Gates considers all of the quality metrics for a project and assigns a passed or failed designation for that project.

How can I get quality gate pass in SonarQube?

Under Quality Gates, pick the Gate you wish to use as your base, click Copy, give it a name; "Copy". Choose Add Condition, choose scope (New or Overall Code), Quality Gate criteria from the drop-down options, failure threshold; "Add Condition".


1 Answers

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    
like image 186
Nikit Swaraj Avatar answered Dec 26 '22 10:12

Nikit Swaraj