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
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.
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.
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):
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.