Blog Detail

Covid-19 Tracker Ask Question

preview image DevOps
by Anurag Srivastava, Jun 21, 2018, 4:58:11 AM | 3 minutes |

Configure SonarQube Scanner with Jenkins

In my previous blogs, I have covered about Jenkins and SonarQube where I have explained their features, installation, and configuration. Now in this blog, I will cover how you can configure SonarQube scanner in Jenkins so that before deploying the code you can scan it through SonarQube and stop the deployment process if the test fails from SonarQube.

This way we can also ensure the code quality before deploying it to the server. So let's start the process of integrating the SonarQube scanner in Jenkins.

Before starting this process please ensure that you have installed SonarQube and Jenkins on your machine. In case you have not installed them please refer to my previous blogs on SonarQube and Jenkins:

Jenkins Setup

Use the following steps for configuring SonarQube with Jenkins:

  • Open Jenkins on your browser and login using the credentials. 

  • Click on 'Manage Jenkins' on the left menu. This will open the Manage Jenkins page with different options.

  • Click on the 'Manage Plugins' option from the list.

  • Now click on the 'Available' tab to search for the plugin.

  • Type 'SonarQube' in the filter text box and hit enter.

  • From the list click on the install button of 'SonarQube Scanner for Jenkins' plugin, please refer to the below screenshot:

  • This will install the SonarQube scanner plugin.

  • Now go to the project page and click on the 'Configure' link from the left menu.

  • Scroll down to the 'Execute SonarQube Scanner' section under build.

  • You can enter the optional fields like the task to run, JDK, and path to project properties.

  • Under analysis properties option add following code and change it as per your project configuration:

sonar.exclusions=vendor/**, storage/**, resources/**

If your SonarQube server is located on a different cluster then provide the SonarQube server location in the Jenkins configuration:

Your SonarQube scanner integration has been done now to build your project to check the SonarQube scan result under console output. The following screen shows the SonarQube result from Jenkins:

I hope this blog can help you to set up the SonarQube scanner with Jenkins. In case of any doubt please leave a comment.

Comments (9)

  • user image
    Daniel Izquierdo
    Aug 28, 2018, 8:12:22 AM

    If I have a Sonarqub?e installation on a cluster how do I tell jenkins where my Sonarqube installation is?

  • user image
    Anurag Srivastava
    Sep 1, 2018, 1:24:44 PM

    Hi Daniel for that you need to provide the SonarQube cluster URL during Jenkins configuration.

  • user image
    Anurag Srivastava
    Sep 1, 2018, 1:29:15 PM

    The setting which you need in the property file

  • user image
    Rajendra N
    Sep 9, 2018, 3:02:46 AM

    How to setup https for sonarqube?

  • user image
    Prudhvi Vem
    Sep 13, 2018, 8:25:39 PM

    I have changed the sonar source and I encounter the below error.ERROR: Invalid value of sonar.sources for com.****.it.***:xyz I have used the file that I have in my Bitbucket. Am I missing something here?

  • user image
    jitender yadav
    Mar 27, 2019, 5:28:00 AM

    Hi Anurag, can you please answer the above queries??

  • user image
    Anurag Srivastava
    Mar 29, 2019, 7:45:52 PM

    @Prudhvi: Basically we use sonar source to provide comma-separated paths to directories containing main source files. It may not be able to read your Bitbucket repository. You can try by cloning your code on Jenkins or any other server and then referring to the code path.

  • user image
    harsh patil
    Apr 16, 2019, 12:04:36 PM

    Hi Anurag, im trying to run sonarqube scanner for a project with jenkins integretion, i got stucked with below Error, 16:27:38 SonarQube Runner 2.4 16:27:38 Java 1.8.0_201 Oracle Corporation (64-bit) 16:27:38 Linux 4.15.0-1035-aws amd64 16:27:38 INFO: Runner configuration file: /opt/sonarscanner/conf/ 16:27:38 INFO: Project configuration file: NONE 16:27:38 INFO: Default locale: "en", source code encoding: "UTF-8" 16:27:38 INFO: Work directory: /var/lib/jenkins/workspace/Example_of_SonarQube_Scanner_Usage/.sonar 16:28:08 INFO: ------------------------------------------------------------------------ 16:28:08 INFO: EXECUTION FAILURE 16:28:08 INFO: ------------------------------------------------------------------------ 16:28:08 Total time: 30.112s 16:28:08 Final Memory: 1M/59M 16:28:08 INFO: ------------------------------------------------------------------------ 16:28:08 ERROR: Error during Sonar runner execution 16:28:08 ERROR: connect timed out 16:28:08 ERROR: Caused by: connect timed out can you pls suggest something! Thank you!

  • user image
    Anurag Srivastava
    Apr 16, 2019, 2:16:09 PM

    @harsh: seems that the report zip size is big and scanner is unable to upload that. If there is any library directory which we can ignore then please add it under sonar.exclusions option. let me know if it works for you.

Leave a comment

Related Blogs

Introduction to Cloud Computing

Sep 23, 2020, 2:38:00 PM | Anurag Srivastava

Monitoring website uptime using Kibana

Sep 6, 2020, 5:20:33 PM | Anurag Srivastava

Monitoring Application using Elastic APM

Jan 16, 2020, 11:43:29 AM | Anurag Srivastava

Configuring Django application with Elastic APM

Jan 14, 2020, 10:22:34 AM | Anurag Srivastava

Introduction to Elastic APM

Jan 7, 2020, 7:15:34 PM | Anurag Srivastava

Why monitoring is important?

Jan 6, 2020, 7:30:13 PM | Anurag Srivastava

Top Blogs

Configure SonarQube Scanner with Jenkins

Jun 21, 2018, 4:58:11 AM | Anurag Srivastava

Execute Commands on Remote Machines using sshpass

Jul 16, 2018, 5:00:02 PM | Anurag Srivastava

Importing MongoDB data into Elasticsearch

Mar 9, 2019, 8:20:38 AM | Anurag Srivastava

Importing MySQL data into Elasticsearch

Feb 9, 2019, 12:06:18 PM | Anurag Srivastava

Configure Jenkins for Automated Code Deployment

Jun 13, 2018, 3:44:01 PM | Anurag Srivastava

Deploying Angular code using Python script

Jun 26, 2018, 4:50:18 PM | Anurag Srivastava