Azure DevOps: how to break CI build if quality gate conditions fail to meet

SonarQube : * Enterprise Edition* Version 8.4.1 (build 35646),
Scanner: 4.3.0.2102

  • what are you trying to achieve : Fail CI build if the analysis of project fail to meet quality gate

  • what have you tried so far to achieve this: we tried a python script to call the API for project status and fail the build accordingly. But it would be great if we have option via sonar scanner itself

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.

Check this video here to learn how.

Cheers,
Daniel

Hello Daniel,

Thanks for your response. We do have the PR rules setup done. But as per Org practices, we would like to have this feature as well.

Hi,

This is not possible today. As explained in our docs:

How can I break the build based on the Quality Gate status?
We believe that breaking a CI build is not the right approach.

Instead, we are providing pull request decoration (to make sure that issues aren’t introduced at merge time) and we’ll soon add a way to check the quality gate as part of a Release process.

Cheers,
Daniel

I was able to get a pipeline build in Azure DevOps to fail when the Quality Gate fails simply by adding these 2 properties to the SonarQubePrepare task (under its extraProperties attribute):

sonar.qualitygate.wait=true
sonar.qualitygate.timeout=300

See Overview | SonarQube Docs for more info. The preferred technique still seems to be not to cause individual builds to fail however. Rather SonarSource want you to use a branch policy to block a merge into your master branch if your PR fails to meet the Quality Gate, as @Daniel_Meppiel has already said.