Installation of SonarQube + Jenkins | CodeUsingJava








We'll look at how to integrate sonar cube report with the Jenkins in this session


In previous tutorial we have seen how to integrate sonar scanner with maven. We will automate the same process here using the Jenkins.
In this tutorial we will need version control tool. I will be using git and github. I will create a centralized repository using the github where all the developers are going to check in their code and Jenkin will take that code and scan it using sonar scanner plus it is going to publish the report.
Now let us have look at how to install jenkins: First go to site "https://jenkins.io/download/" I have downloaded following verion

sonar5_1

Extract the zip and start the installation.

sonar5_2

It will show the destination folder for installation.

sonar5_3

Click on install to start the installation.

sonar5_4

Wait till the installation is finished

sonar5_5

Once installation in over click finish button.

sonar5_6

It will automatically open "localhost:8080/login" in browser after clicking on finish button. Go to the path specified in above image, copy the password and click on continue

sonar5_7

It will ask you what kind of installation you need. I have choosen "install suggested plugins". You can select plugins also which are required to you.

sonar5_8

It will take some time to install the plugins.

sonar5_9

Following plugins will be installed.

sonar5_10

It will ask to create a user fill the details or you can even continue as admin.

sonar5_11

You can also change the port number here. or skip this step.

sonar5_12

Now Jenkins is ready to user

sonar5_13

This will be your dashboard

sonar5_14

If you use github as a version control, please make sure you have the following settings on your Jenkins Go to Manage Jenkins

sonar5_15

Go to global tool configuration. Here you will have section for git.

sonar5_16

Here you need to give path to the executable. Wherever you have installed the git in your local machine give the path here. Click on save.

sonar5_17

Next is, If you want to be notified about the build is success or failure of the report by email. Go to Configure System

sonar5_18

Scroll down to last, you will see section for E-mail Notification

sonar5_19

Here you need to fill the details required. You can even test from this section if the email notification is successfull or not by clicking on test configuration. Before that you need to fill all the details.

sonar5_20

Now we will create a new job. Click on New Item. Below window will open. Enter the item name

sonar5_21

Select Freestyle project and click Ok

sonar5_22

We need to execute the project which is deployed on the github. I already have previous tutorails maven project on github

sonar5_23

In general you need to enter git project url

sonar5_24

Now go to source code management tab below. Here we will be using git. Select git You need to give the repository url and credentials to access that url.

sonar5_25

To add credentials you need to click on add.

sonar5_26

It will open below window. Give your username and password for the github accout. Click add.

sonar5_27

Next is Build Triggers. Build can be specified in different ways. Even manually you can build. From the following options you can select when you have to build like build periodically or even when new changes are pushed then also it can build. Based on your requirements you can select these things.

sonar5_28

Next part is Build Environment. Here also there are different options you can select for example delete workspace before build starts or abort build if it's stuck

sonar5_29

Next is Build. How you are going to build your project. Here what you can do select the option from below.

sonar5_30

I have selected execute on window batch command. Here I am specifying "mvn clean sonar:sonar". Our project already have the sonar maven plugin. So sonar scanner will automatically nalyze the code and publish the report. Instead of running manually from the command line now, we're going to automate this process with the Jenkins

sonar5_31

Last is Post-Build Actions. You can enable it here if you wish to receive an email notification about the build. Here there are various options like publish JUnit Reports, send build status on git etc. Click on Save.

sonar5_32

Before you build you need to start the SonarQube server "StartSonar.bat"

sonar5_33

After the sonarqube is started click on Build Now. It will run the commad we have provided.

sonar5_34

After build is complete it will show like below screen. Click on #1

sonar5_35

It will show below window.

sonar5_36

Click on Console Output, it will give all the details. Scroll till last there will be a sonar qube link click on it.

sonar5_37

It will open below screen

sonar5_38

Hope you understand the concept of how to integrate the sonarqube scanner with the Jenkins and how to automate the construction process