使用 SonarQube 5.2 构建断路器插件
Build Breaker Plugin with SonarQube 5.2
似乎 Build Breaker Plugin 不再与 SonarQube 5.2 兼容。如果未满足 Sonar 门,是否有任何替代方法可以使 (VSO) 构建失败,或者是否有计划将 Build Breaker 插件更新到 5.2?
没有(目前)任何插件会在 Quality Gate 未通过 SonarQube 5.2 时破坏构建。
但对于 SonarQube 5.3+,您可以再次使用 Build Breaker 插件。
来自邮件列表:
Breaking the build in SonarQube 5.2 (21/Oct/2015)
Fabrice Bellingrad: The Build Breaker
Plugin
won't be available for SQ 5.2+. The idea is to develop a core feature
to answer the use cases previously covered by this plugin. This is
what we call the "what if" feature =>
https://jira.sonarsource.com/browse/SONAR-6763
本期SONAR-6763 is planned for SonarQube 6.X.
在 SonarQube 5.2 中,我们找到了使用 Web 服务的替代方法 /api/events。
请求示例:
https://<sq-host>/api/events?categories=Alert&resource=<project_key>
响应示例:
<events>
<event>
<id>50411</id>
<name>Red (was Green)</name>
<resourceKey>project_key</resourceKey>
<category>Alert</category>
<date>2015-09-29T22:38:44+0200</date>
<description>New Critical issues > 0 since previous analysis (2015 Sep 23), New Major issues > 0 since previous analysis (2015 Sep 23), New issues > 0 since previous analysis (2015 Sep 23)</description>
</event>
....
</events>
正在检测项目的RED状态:
要验证 RED 状态,您需要从响应中找到 events
列表中具有最高 id
值的 event
,然后验证此事件的 name
是否开始来自 Red
,如果你找到它,你将需要失败构建。
此类验证可以仅在 CI 服务器上使用 SQ 步骤后的附加命令行步骤完成,也可以从构建自动化系统完成,例如 Maven or Gradle.
我们还没有在我们的项目中实现这样的解决方法,只是因为没有空闲时间,但我们会在不久的将来实现。
在问题 SONAR-6763 完成之前,建议的解决方案应仅用作解决方法。
在 SonarQube 5.3 中引入了一个新的 Quality Gates Web Service,它可以被调用并用于破坏构建。
To break the CI build for a failed Quality Gate, use WS API calls in a loop to wait until processing is finished, and then check Quality Gate web service:
- call the analysis's ceTaskUrl and examine the "status" value:
- PENDING or IN_PROGRESS - check again later
- FAILED or CANCELED - break the build?
- SUCCESS - move forward
- call Quality Gate web service for status
我还添加了一个 issue to enhance the VSTS Tasks with an option to automatically call this service。
更新: recent PR 将此功能添加到 VSTS 任务(尚未发布)
您现在可以使用 SonarQube Build Breaker Plugin 版本 SonarQube 版本 5.3+。
似乎 Build Breaker Plugin 不再与 SonarQube 5.2 兼容。如果未满足 Sonar 门,是否有任何替代方法可以使 (VSO) 构建失败,或者是否有计划将 Build Breaker 插件更新到 5.2?
没有(目前)任何插件会在 Quality Gate 未通过 SonarQube 5.2 时破坏构建。
但对于 SonarQube 5.3+,您可以再次使用 Build Breaker 插件。
来自邮件列表:
Breaking the build in SonarQube 5.2 (21/Oct/2015)
Fabrice Bellingrad: The Build Breaker Plugin won't be available for SQ 5.2+. The idea is to develop a core feature to answer the use cases previously covered by this plugin. This is what we call the "what if" feature => https://jira.sonarsource.com/browse/SONAR-6763
本期SONAR-6763 is planned for SonarQube 6.X.
在 SonarQube 5.2 中,我们找到了使用 Web 服务的替代方法 /api/events。
请求示例:
https://<sq-host>/api/events?categories=Alert&resource=<project_key>
响应示例:
<events>
<event>
<id>50411</id>
<name>Red (was Green)</name>
<resourceKey>project_key</resourceKey>
<category>Alert</category>
<date>2015-09-29T22:38:44+0200</date>
<description>New Critical issues > 0 since previous analysis (2015 Sep 23), New Major issues > 0 since previous analysis (2015 Sep 23), New issues > 0 since previous analysis (2015 Sep 23)</description>
</event>
....
</events>
正在检测项目的RED状态:
要验证 RED 状态,您需要从响应中找到 events
列表中具有最高 id
值的 event
,然后验证此事件的 name
是否开始来自 Red
,如果你找到它,你将需要失败构建。
此类验证可以仅在 CI 服务器上使用 SQ 步骤后的附加命令行步骤完成,也可以从构建自动化系统完成,例如 Maven or Gradle.
我们还没有在我们的项目中实现这样的解决方法,只是因为没有空闲时间,但我们会在不久的将来实现。
在问题 SONAR-6763 完成之前,建议的解决方案应仅用作解决方法。
在 SonarQube 5.3 中引入了一个新的 Quality Gates Web Service,它可以被调用并用于破坏构建。
To break the CI build for a failed Quality Gate, use WS API calls in a loop to wait until processing is finished, and then check Quality Gate web service:
- call the analysis's ceTaskUrl and examine the "status" value:
- PENDING or IN_PROGRESS - check again later
- FAILED or CANCELED - break the build?
- SUCCESS - move forward
- call Quality Gate web service for status
我还添加了一个 issue to enhance the VSTS Tasks with an option to automatically call this service。
更新: recent PR 将此功能添加到 VSTS 任务(尚未发布)
您现在可以使用 SonarQube Build Breaker Plugin 版本 SonarQube 版本 5.3+。