Build Breaker Plugin with SonarQube 5.2

感情迁移 提交于 2019-11-30 03:53:44

There is not (for now) any plugin which will break build when Quality Gate did't pass on SonarQube 5.2.

But for SonarQube 5.3+ you can again use Build Breaker plugin.


From mailing list:

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

This issue SONAR-6763 is planned for SonarQube 6.X.

You can now use the SonarQube Build Breaker Plugin with version SonarQube version 5.3+.

In SonarQube 5.2 we found alternative way in usage of Web Service /api/events.


Request example:

https://<sq-host>/api/events?categories=Alert&resource=<project_key>

Response example:

<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>

Detecting RED status of the project:

To verify RED status you will need to find event with highest id value in events list from response and then verify that name of this event is starting from Red and if you will find it you will need to fail build.

Such verification can be done just on CI server using additional command line step after SQ step or it can be done from build automation system like Maven or Gradle.


We didn't implement such workaround yet in our project, just because of lack free time, but we will do this in near future.

Proposed solution should be used only as workaround until issue SONAR-6763 will be done.

With SonarQube 5.3 a new Quality Gates Web Service was introduced which could be called and used to break the build.

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

I've also added an issue to enhance the VSTS Tasks with an option to automatically call this service.

Update: A recent PR added this feature to the VSTS Task (not released yet)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!