Is there a way to configure Sonar or the Sonar Maven plugin to make a build fail when a violation of a certain priority (Blocker, Critical) is detected?
Analyzing a Maven project consists of running a Maven goal: sonar:sonar from the directory that holds the main project pom.xml. You need to pass an authentication token using the sonar.login property in your command line. mvn clean verify sonar:sonar -Dsonar.login=myAuthenticationToken
As a passing build is a requirement for the merge into the master, you have ensured that no broken code (at least how SonarQube sees it) ever reaches the master branch. Unfortunately the SonarQube developers don’t agree with me on that.
Excluding a module from analysis 1 define property <sonar.skip>true</sonar.skip> in the pom.xml of the module you want to exclude 2 use build profiles to exclude some module (like for integration tests) 3 use Advanced Reactor Options (such as "-pl"). For example mvn sonar:sonar -pl !module2
When running the SonarQube analysis on the pull-request and the quality gate turns red, the build of this branch fails. As a passing build is a requirement for the merge into the master, you have ensured that no broken code (at least how SonarQube sees it) ever reaches the master branch.
you have to define alert thresholds on the number of blocker/critical violations (>0 is your case) in quality profile and install the build breaker plugin (category "Integration" in Update Center of sonar 2.4).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With