Blog Detail

preview image DevOps
by Anurag Srivastava, Jun 21, 2018, 4:58:11 AM | 2 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 is fail from SonarQube.

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

Before staring 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 following steps for configuring SonarQube with Jenkins:

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

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

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

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

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

  • From the list click on install button of 'SonarQube Scanner for Jenkins' plugin.

  • This will install the SonarQube scanner plugin.

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

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

  • You can enter the optional fields like 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.projectKey=project12345
sonar.projectName=project_test
sonar.projectVersion=1.0
sonar.login=admin
sonar.password=admin
sonar.exclusions=vendor/**, storage/**, resources/**
sonar.language=php
sonar.sources=/var/lib/jenkins/workspace/$JOB_NAME
sonar.sourceEncoding=UTF-8

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

sonar.host.url=http://192.168.12.24:9000/sonar


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

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




About Author

Anurag Srivastava

Author | Blogger | Tech Lead | Data Scientist | Innovator |

View Profile

Comments (5)

  • 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 is:sonar.host.url=http://192.xxx.xx.xx:9000/sonar

  • 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?

Leave a comment

Related Blogs

Load csv Data into Elasticsearch

Oct 15, 2018, 6:25:43 PM | Anurag Srivastava

htop: An Interactive Process Viewer

Oct 13, 2018, 8:49:59 PM | Anurag Srivastava

Configure Logstash to push MySQL data into Elasticsearch

Jul 7, 2018, 8:51:30 AM | Anurag Srivastava

Execute Commands on Remote Machines using sshpass

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

Configure Jenkins for Automated Code Deployment

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

Build and deploy Angular code using Python

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

Why SonarQube is important for IT projects ?

Apr 24, 2018, 2:52:28 PM | Anurag Srivastava

SonarQube installation on Ubuntu

May 12, 2018, 4:47:07 PM | Anurag Srivastava

Install Kafka on Ubuntu

Jul 12, 2018, 7:40:51 PM | Anurag Srivastava

Analyze your project with SonarQube

Jun 2, 2018, 10:49:54 AM | Anurag Srivastava

Top Blogs

Build and deploy Angular code using Python

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

Configure SonarQube Scanner with Jenkins

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

Configure Logstash to push MySQL data into Elasticsearch

Jul 7, 2018, 8:51:30 AM | Anurag Srivastava

Configure Jenkins for Automated Code Deployment

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

SonarQube installation on Ubuntu

May 12, 2018, 4:47:07 PM | Anurag Srivastava

Execute Commands on Remote Machines using sshpass

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

Why SonarQube is important for IT projects ?

Apr 24, 2018, 2:52:28 PM | Anurag Srivastava

Install Jenkins on Ubuntu

May 26, 2018, 6:42:02 PM | Anurag Srivastava

Analyze your project with SonarQube

Jun 2, 2018, 10:49:54 AM | Anurag Srivastava

Install Kafka on Ubuntu

Jul 12, 2018, 7:40:51 PM | Anurag Srivastava