Shivansh Kumar
Shivansh Kumar

Reputation: 361

How to fail a maven build, when quality gate fails?

Earlier I use sonar-maven-plugin version 3.2 then when a Sonar quality gate fails the build also used to fail. Now I am using sonar-maven-plugin version 3.7.0.1746, it does not happen so. Even if quality gate fails maven build succeeded. Now when I use version 3.2 in pom.xml it gives the error

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

While using sonar-maven-plugin version 3.7.0.1746 doesn't give the above error.

This is how I add the plugin in Pom.xml

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

I also got to know that in version 3.2 there was some post-job action like org.sonar.plugins.buildbreaker.QualityGateBreaker.

How can it be done now? I am using https://sonarcloud.io/ for sonar.

Upvotes: 5

Views: 2701

Answers (1)

kaan bobac
kaan bobac

Reputation: 747

If Sonar Qube Server version is bigger than 8.1, sonar.qualitygate.wait=true can be used:

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

Otherwise, there is a maven plugin to detect Sonar Quality Gate Result:

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

Then, you will run the following Maven Command:

mvn sonar-quality-gate:check

Upvotes: 3

Related Questions