简体   繁体   English

SonarQube - 增加自定义质量门

[英]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.我已经将 sonarqube 企业配置到我的项目管道中,并且在质量门下的 sonarqube 中我找不到添加新的质量门,也无法在现有的质量门中添加条件。 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. 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:这里有两个 web API:

  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.注意:您需要Administer Quality Gates权限才能执行这两个 API。

This is an achieved under the UI and via the API .这是在UI下通过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. LTS 8.9.0 至 21 年 5 月的详细信息。

VIA API:威盛 API:

Check your installation web_api reference (because SQ does not publish it independently to the web and they change it often).检查您的安装 web_api 参考(因为 SQ 不会将其独立发布到 web 并且他们经常更改它)。

Create a Quality Gate:创建质量门:
POST {sq_url}/web_api/api/qualitygates/create ?name=<value> 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> 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> 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;在 Quality Gates 下,选择您希望用作基础的 Gate,单击 Copy,为其命名; "Copy". “复制”。

添加门

Choose Add Condition, choose scope (New or Overall Code), Quality Gate criteria from the drop-down options, failure threshold;选择添加条件,从下拉选项中选择 scope(新代码或整体代码),质量门标准,故障阈值; "Add Condition". “添加条件”。 Repeat as necessary.根据需要重复。

添加自定义条件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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