3
votes

We are using Jenkins as our CI server, and Sonarqube for code analysis.

Currently we are using SonarQube 4.5.7 and we want to upgrade to version 6.5. We have several quality gates, and we can't find an automatic way to assign the quality gate to the project.

In previous version we used the sonar.QualityGate property, but this property is now deprecated.

How can we let Jenkins setup the quality gate before it starts the analysis?

1
the field is still working :D but you could use the APISimon Schrottner
do you have branchbased analysis running? else you can simply set the profile once within the admin panel of the project and it will stick to it.-> if you use like sonar4stash as a bitbucket plugin, this can also set your profiles and gates according of the target branchSimon Schrottner
@SimonSchrottner I just try to use it add a non exist quality gate and it ignore it. we run sonar for every branch this is the reason why we need to add the gate dynamically , do you have any api usage example , I can't make it work ...Mor Lajb
next.sonarqube.com/sonarqube/web_api -> you can find all the necessary informations there normally...Simon Schrottner
Why do you have to set the quality gate automatically? Do you change it regularly? Or do you drop your project before each analysis?slartidan

1 Answers

1
votes

Use the sonar.branch property to run branch the analysis. I guess (not tested) that the main project's quality gate will apply.

If that is not an option for whatever reason, use curl to provision the project and to set the quality gate:

curl -s -u admin:admin -XPOST "localhost:9000/api/projects/create?project=b&name=bla"  | python -m json.tool
curl -s -u admin:admin -XPOST "localhost:9000/api/qualitygates/select?projectKey=b&gateId=1"  | python -m json.tool