Sonar + Maven + Jenkins integration

Asked

Viewed 136 times

1

Good morning, everyone, I am setting up an integration server using Jenkins + Maven + Sonar Quebe, but I have the following scenario: 1 - If junit tests fail, Maven stops deploying the application. Blz is the expected result. 2 - If sonar points problems in my code (bug) the Maven does not stop and deploy normally.

My question is whether there is a way to make Maven not deploy when sonar indicates a bug or even if possible a maximum number of bugs

Thanks in advance.

1 answer

1


There are some options for you to use using your version of Jenkins, for older versions this Quality Gates checking functionality was done manually through scripts.

1. Quality Gate Plugin

A simple integration through of this plugin, you can configure it in few steps as shown in official documentation

2. Webhooks

From version 6.2 of Sonar this check can be done through webhooks, as shown this article

3. Shell Script

As pointed out by ansolsi Zied on this thread, you can check using the script below:

if [ "\`curl -sL -w %{http_code} http://sonar_host/api/qualitygates/project_status?projectKey=project_key -o /dev/null -S --quiet 2>&1 | jsawk -a 'return this.status'\`" == "ERROR" ]; 
then 
  exit 1; 
fi;

Replacing project_key key to your Sonar registered project


In previous versions of Sonar, there was a plugin called Build Breaker Plugin, it has been discontinued and here you can read a sonar article explaining why it should no longer be used.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.