Jenkins Integration with SonarQube Tutorial

Devansh Markan
3 min readNov 19, 2020

--

Welcome back! Continuing with one of the most amazing tools in DevOps, i.e SonarQube. This time, we are going to integrate SonarQube with Jenkins. We have already explored Jenkins and some of its experiments in some previous tutorials, so you can also refer it from there.

First of all, Start Jenkins with the following command :

So, go to the directory where your jenkins.war file is present. Start the Jenkins service using the java -jar jenkins.war command in the command prompt in administrator mode.

It will look like this:

Now, Go to the Jenkins dashboard at localhost:8080 and Jenkins will open and will ask for your username and password.

All you have to do is : 1. Click on the new item option

2. Select the “MAVEN”project option

3. Give a name to the project and press save.

It will look like this:

After pressing enter, a configuration dashboard will open and there comes the major part.

Click on the Source Code Management tab to add the Github repository and thereby, integrate Jenkins and Github.

Follow the below steps:

In the Source Code Management Section, select Git as your option.

Visit the repository where you saved your project and copy the location of your github repository.

Give the repository location in the specified placeholder.

Provide the complete path of the pom.xml file.

If it lies inside a folder use {folder_name}/pom.xml

Now comes the major part of the experiment.

The Jenkinsfile for the project must contain a stage that defines the following command:

mvn sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.analysis.mode=publish

This file is the Jenkinsfile which contains this above-mentioned command:

Now, after you submit, you will be enter into a dashboard and then you will have to click on Build Now option. Click the option of console output to check the build process.

After this whole process is done, the code has been deployed on SonarQube and it will perform static code analysis on it. The output as seen in the console output of Jenkins.

A URL is also generated with which we can see the report.

So, this is the report which we wanted to see with the help of SonarQube. That’s all for this tutorial. Thank You.

--

--

Devansh Markan
Devansh Markan

Written by Devansh Markan

Tech-enthusiast and looking for learning new technologies and writing technical blogs here.

No responses yet