Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make Hudson/Jenkins fail if Sonar thresholds are breached?

I am using maven to build my java app, Jenkins for CI and Sonar for metrics.

Currently I have a build job that creates the sonar report. (Triggered via a post-build step in Jenkins.)

I would like to set this up to fail the build if certain thresholds are met - i.e. any major or blocker violations or Complexity more than 1.7.

Any guidance would be appreciated! - L

like image 899
laura Avatar asked Jan 20 '12 14:01

laura


2 Answers

Use Jenkins Quality Gates Plugin, which fails the build if the predefined sonar quality gates are not green.

  1. Plugin ID quality-gates
  2. Latest Release 2.5
  3. Latest Release Date May 17, 2016
  4. Required Core 1.625.3

This plugin will stop a job when a quality gate measures is detected.

like image 121
johnnymnmonic Avatar answered Oct 20 '22 12:10

johnnymnmonic


Install the build breaker plugin.

Fails your build if the code breaches any of the alert thresholds you specify on the project's Sonar quality profile.

Update

Sonarqube no longer recommends the use of this plugin:

  • http://www.sonarqube.org/why-you-shouldnt-use-build-breaker/

Update (2019-02-11)

It appears the product has changed since I wrote this answer 7 years ago

  • https://blog.sonarsource.com/breaking-the-sonarqube-analysis-with-jenkins-pipelines/
like image 36
Mark O'Connor Avatar answered Oct 20 '22 11:10

Mark O'Connor