1

I’m using SonarQube Version 6.7.3 (build 38370). I’m NOT using the new branch support.

I’m trying to implement automated builds of pull requests, integrating BitBucket and Jenkins with SonarQube. As I’m not using the new branch support, I’m setting “sonar.branch” instead of “sonar.branch.name”. As a result of this, I get a separate project for the pull request. This is ok, as I have automation that deletes the SonarQube project when the pull request branch is deleted (when it is merged).

What isn’t working correctly is that the pull request SonarQube project sometimes gets the wrong quality gate assigned to it on first creation. It’s not acceptable to have to modify it after the fact. If the wrong quality gate is assigned, and the correct thresholds are not observed, the pull request could be marked as mergeable, even though it violates our quality guidelines.

I know the name of the required quality gate. Is there a Sonar property I can set in the build (using the Maven plugin), which will ensure that the resulting project has the correct quality gate?

If there’s no way to include this information on the initial scan, is it possible to call the SonarQube REST api before I run the scan, to ensure the project is created, and set the quality gate for it, and then run the scan?

I can’t find the documentation for the REST api for recent versions.

I noticed https://docs.sonarqube.org/pages/viewpage.action?pageId=2752810#WebService/api/qualitygates-AssociateaProjecttoaQualityGate , but that appears to be obsolete. That page has a link to the new documentation, but I don’t see any description of the REST api there.

David M. Karr
  • 14,317
  • 20
  • 94
  • 199
  • It's not possible to set qualitygate from properties/parameters. You can check current api documentation on your own server like: http://server_name:9000/web_api/ Check both answers from here: https://stackoverflow.com/q/36347106/7225096 – Peska Jul 12 '18 at 06:36
  • you can find recent documentation for the rest api under "?" icon on homepage of SQ (api/qualitygates/select ) – Josef Prochazka Jul 12 '18 at 09:57

1 Answers1

2

You can use the api/qualitygates/select service:

Associate a project to a quality gate. The 'projectId' or 'projectKey' must be provided. Project id as a numeric value is deprecated since 6.1. Please use the id similar to 'AU-TpxcA-iU5OvuD2FLz'. Requires the 'Administer Quality Gates' permission.

Parameters:

  • gateId (required) - quality gate id; example: 1
  • projectId (optional) - project id (project id as an numeric value is deprecated since 6.1); example: AU-Tpxb--iU5OvuD2FLy
  • projectKey (optional) - project key; example: my_project

You should do the following steps in order:

  1. create a project api/projects/create
  2. associate it with a quality gate api/qualitygates/select
  3. associate it with a quality profile api/qualityprofiles/add_project
  4. run an analysis
agabrys
  • 8,728
  • 3
  • 35
  • 73