Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonar Maven plugin - fail the build on violation

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?

like image 523
Axel Fontaine Avatar asked Dec 01 '10 12:12

Axel Fontaine


People also ask

How to analyze a Maven project using sonar?

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

What is a passing build in SonarQube?

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.

How to exclude a module from analysis in sonar?

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

What happens when the quality gate turns red in SonarQube?

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.


1 Answers

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).

like image 129
Simon Brandhof - SonarSource Avatar answered Sep 28 '22 08:09

Simon Brandhof - SonarSource