Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fail Gradle Build for Sonar Violations

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?

like image 359
Mike Rylander Avatar asked May 29 '14 14:05

Mike Rylander


People also ask

How to run a sonar analysis from a Gradle build?

Execute gradle sonarqube -Dsonar.login=yourAuthenticationToken and wait until the build has completed, then open the web page indicated at the bottom of the console output. You should now be able to browse the analysis results.

How to pass authentication token to Gradle sonar?

You need to pass an authentication token using the sonar.login property in your command line or you configure it as part of your gradle.properties file. Execute gradle sonarqube -Dsonar.login=yourAuthenticationToken and wait until the build has completed, then open the web page indicated at the bottom of the console output.

Why is Gradle--version not working?

Other installation failures If gradle --version works, but all of your builds fail with the same error, it is possible there is a problem with one of your Gradle build configuration scripts. You can verify the problem is with Gradle scripts by running gradle help which executes configuration scripts, but no Gradle tasks.

Why can't I see Gradle in my system?

If not, here are some things you might see instead. If you get "command not found: gradle", you need to ensure that Gradle is properly added to your PATH. If you get something like: ERROR: JAVA_HOME is set to an invalid directory Please set the JAVA_HOME variable in your environment to match the location of your Java installation.


2 Answers

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

like image 96
Martin Letendre Avatar answered Oct 19 '22 15:10

Martin Letendre


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.

like image 31
Peter Niederwieser Avatar answered Oct 19 '22 16:10

Peter Niederwieser