简体   繁体   中英

SonarQube -adding custom quality gate

I have a requirement to add custom quality gate condition on my project. If that is not met then my build should fail. I have already configured sonarqube enterprise to my project pipeline, and in sonarqube under quality gates I couldn't find add new quality gate and also couldn't add conditions in the existing quality gate. Please help me with this. And also what would be the best conditions that can be provided as if it doesn't pass then build has to fail

You can use SonarQube's web API or REST API to add new quality gate and also to add conditions in the existing quality gate.

Here are two web API's:

  1. To create quality gate

POST api/qualitygates/create

  1. To add conditions in the existing quality gate

POST api/qualitygates/create_condition

Note: You need the Administer Quality Gates permission to execute both the API's.

This is an achieved under the UI and via the API . You cannot modify the Built-In Gate, but you can copy it, modify the copy and set that as the default. Requires the ' Administer Quality Gates ' permission. Details as of LTS 8.9.0 - May '21.

VIA API:

Check your installation web_api reference (because SQ does not publish it independently to the web and they change it often).

Create a Quality Gate:
POST {sq_url}/web_api/api/qualitygates/create ?name=<value>

Add a new condition to a quality gate:
POST {sq_url}/web_api/api/qualitygates/create_condition ?metric=<condition>&error=<threshold>

Set a quality gate as the default quality gate:
POST {sq_url}/web_api/api/qualitygates/set_as_default ?name=<value>

VIA UI:

Under Quality Gates, pick the Gate you wish to use as your base, click Copy, give it a name; "Copy".

添加门

Choose Add Condition, choose scope (New or Overall Code), Quality Gate criteria from the drop-down options, failure threshold; "Add Condition". Repeat as necessary.

添加自定义条件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM