【问题标题】:How to fail a maven build, when quality gate fails?当质量门失败时,如何使 Maven 构建失败?
【发布时间】:2020-07-14 12:27:57
【问题描述】:

之前我使用sonar-maven-plugin version 3.2,然后当声纳质量门失败时,构建也会失败。现在我正在使用sonar-maven-plugin version 3.7.0.1746,但事实并非如此。即使质量门失败,maven 构建也成功。现在,当我在 pom.xml 中使用 3.2 版时,它会给出错误

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar (default-cli) on project maven-webapp: Unable to execute SonarQube: Fail to download libraries from server -> [Help 1]

虽然使用sonar-maven-plugin version 3.7.0.1746 不会出现上述错误。

这就是我在 Pom.xml 中添加插件的方式

<plugin>
     <groupId>org.sonarsource.scanner.maven</groupId>
     <artifactId>sonar-maven-plugin</artifactId>
     <version>3.2</version>
</plugin>

我还了解到,在 3.2 版中,有一些工作后操作,例如 org.sonar.plugins.buildbreaker.QualityGateBreaker

现在怎么办? 我将https://sonarcloud.io/ 用于声纳。

【问题讨论】:

  • 如果您找到解决方案,请告诉我们。
  • 我猜这是设计上的改变。至少看起来他们改变了 Jenkins 集成功能,因为 SonarQube 的根本变化使其成为一种不好的使用模式。请参阅:blog.sonarsource.com/why-you-shouldnt-use-build-breaker 此外,他们(重新)为 Jenkins 管道引入了不同的实现:blog.sonarsource.com/… 不过,这些都不完全涵盖 Maven,也不包括 Sonar Cloud。

标签: maven sonarqube maven-plugin sonarcloud


【解决方案1】:

如果Sonar Qube Server版本大于8.1,可以使用sonar.qualitygate.wait=true

mvn verify sonar:sonar -Dsonar.qualitygate.wait=true

否则,有一个maven插件来检测Sonar Quality Gate Result:

 <plugin>
        <groupId>io.github.r0bb3n</groupId>
        <artifactId>sonar-quality-gate-maven-plugin</artifactId>
        <version>1.1.0</version>
  </plugin>

然后,您将运行以下 Maven 命令:

mvn sonar-quality-gate:check

【讨论】:

    猜你喜欢
    • 2016-03-13
    • 2010-11-26
    • 2015-04-25
    • 1970-01-01
    • 2020-11-03
    • 2014-07-03
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    相关资源
    最近更新 更多