Tuesday 23 October 2018

SonarQube with Jenkins

How to integrate Sonarqube with Jenkins (Windows 7/8 64 bit)_


Many of us are working on automation testing where we need to write thousand lines of code to automate test cases. while writting code, one has to follow the standard. One has to put write logic which helps in optimizing your code and performance. 

Here is tool SonarQube which explains about how to install/configure it for continuous integration and improving code quality.

Main reason of using this is opensource platform continuous inspection of code quality.It helps in various task and provide report on duplicate code, code standard, unit test, code coverage, complex code etc...

Let's go over setting up SonarQube with Jenkins.


Pre-requisite:

1) One needs to have Jenkins server 2.138.1 installed and service up and running.
2) Download SonarQube from web and unpack the zip file and copy that folder anywhere on your system.
3) Let's run
C:\Users\<username>\Downloads\sonarqube-7.3.zip\sonarqube-7.3\bin\windowsx86-64\StartSonar.bat
4) One needs to have Maven project which is commited to respective repository and integrated with Jenkins.
5) Go to settings.xml file where maven is installed.
For e.g.
C:\Users\<Username>\apache-maven-3.3.9\conf\settings.xml


Add following in above file..


<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>http://<jenkinsServerIP>:9000
</sonar.host.url>
</properties>
</profile>


6) Add the following dependency in pom.xml file of your respective project.

<build>
<finalName>arcVirtualQueuing</finalName>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.3.0.603</version>
</plugin>
</plugins>
</build> 


1) Login to Jenkins dashboard and click on Mange Jenkins.

2) Go to Manage plugins 


3) Search for SonarQube scanner and install.

4) Again click on Manage Jenkins --> Configure System
Let's keep following configuration which is global to jenkins.

5) Again click on Manage Jenkins --> Configure System

 
















6) Click on Jenkins with the assumption of one have already added new project to
Jenkins.

Following are the configurations:
7) Click on any of project --> Click on Configure from left panel of the screen.







Add following additional properties in Analysis properties box.
#required metadata
sonar.projectKey=<projectName>



8) Do Apply and save

9) Go back to Jenkins --> Click on respective project --> click on Build

After all, you will get SonarQube URL from console output.


1 comment:

Select Language