Reputation: 20119
How do I configure my Gradle build to fail when there are Sonar violations?
I want my Gradle build to fail if there are any are any critical or blocker violations in Sonar, is this functionality supported? If so, is it documented anywhere?
Upvotes: 6
Views: 7364
Reputation: 135742
Add a quality gate to the project and include sonar.qualitygate.wait
:
// build.gradle
sonarqube {
properties {
property("sonar.qualitygate.wait", true)
Source: https://docs.sonarqube.org/latest/analysis/analysis-parameters/ ("Quality Gate", bottom of the page)
Upvotes: 1
Reputation: 79
1) You must install the Build Breaker Plugin on the server side into /path/to/sonarqube/extensions/plugins/ see full instruction here
https://github.com/SonarQubeCommunity/sonar-build-breaker
2) you must use the SonarQube Scanner for Gradle
3) In your gradle config sonar.buildbreaker.skip properties must be false
buildscript {
repositories {
...
maven {
// for sonarqube
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2'
}
}
apply plugin: "org.sonarqube"
sonarqube {
properties {
property "sonar.projectKey", "your.project"
property "sonar.buildbreaker.skip" , "false"
}
}
4) You will probably want to add a Quality Gate in sonarQube (server side). For more information check this
Upvotes: 7
Reputation: 123890
It's not something that can be configured on the build side. Instead, the "build breaker plugin" has to be configured on the Sonar side. I'm not completely sure if it works with Gradle, but I think it does.
Upvotes: 3