SonarQube Quality Gate set from cli

Is it possible to set the sonar project quality-gate at the time of sending the data i.e. through the sonar-scanner-cli ?

I searched and could not find that option which was earlier available.

Is that option disabled?

Basically wanted to set the quality-gate for the respective project-key through scanner-cli

like say I have the below command line

    sonar-scanner -Dsonar.python.coverage.reportPath=coverage.xml
      -Dsonar.host.url=$SONAR_URL
      -Dsonar.projectName=$PROJECT_NAME
      -Dsonar.projectKey=$CI_PROJECT_NAME
      -Dsonar.sources=.
      -Dsonar.python.pylint.reportPath=pylint.txt

So is there an option like sonar.qualitygate that can be provided in the CLI?

2 Likes

Hello Issac,

After analysis is done results are sent to SonarQube instance where compute engine prepares data and then Quality Gate can change status or not depending on settings and analysis.

What exactly do you mean by set the sonar project quality-gate at the time of sending the data? Could you explain more your use case?

Also to which earlier option you are referring to?

Jacek

made update to my question

Thanks for the update!

There is no possibility to change project Quality Gate during scan using properties.

One way to achieve this would be to use WS api/qualitygates/select before running Scanner.

Although I’m still interested about reasons why you would like to change Quality Gate on project during scan?

Thanks for your quick reply.

Well its not to change but to set.

Consider this is the first time the project is ingested into sonar so that way wanted to understand if there was a possibility to set it using the CLI rather than admin intervention.

So the case is that project ownership is mine but sonar administration is by other admin level agents.

So is intervention required by administrator to manually set for each project within dashboard to the quality profile or can it be done through cli while sending to sonar.

Hopefully it is clearer now, I can elaborate further

2 Likes

Hello any reply to this?

To sum up, we don’t provide such property to either set or change Quality Gate in scanner-cli during scan as I’ve mention earlier.

In order to configure Quality Gate for your project, you would have to get at least project administrator permission and do it by UI.

Also when project has been analysed for the first time, a default Quality Gate configured in your SonarQube instance will be set.
For more information regarding Quality Gates see docs.

Also if you feel if that would be a nice feature, I encourage you to suggest it here.

Hi!,
I have a similar need, and I’m checking since it’s been a while from this original post.
Is it possible to modify the code coverage threshold when running sonar-scanner cli when using the community edition?
We are in the early stages of adding tests to one of our existing projects, so our code coverage is around 20%. My intention is to set a low cc threshold to 20% and continue to increase the % when adding more tests.
This needs to be to specific project, other projects are running fine with a higher cc.

Thanks!

2 Likes

Years later, but I stumbled on this thread and im sure others will too.

The solution is that you can add the following param:
-Dsonar.qualitygate.wait=true

For anyone else stumbling on this to try and set the quality gate for the first scan of a project to use, I’ve now created this thread to discuss: Automated scan on new code – How do I specify the quality gate for the first scan to use? - SonarQube - Sonar Community (sonarsource.com)

correct.
We need to define it at first scan too.