All Courses
Install SonarQube in windows and Jenkins integration Tutorial

This topic describes how to install Sonarqube on your Windows computer and Jenkins server integration. How to achieve static code analysis in Jenkins using sonarQubeade will do a hands-on step by step let’s start…

What is Sonarqube?

SonarQube is an open-source tool for managing the code quality of your application. this
Manages seven axes of code quality, including architecture and design, duplication, and unity
Testing, potential bugs, complexity, programming rules, and comments.
Programming languages ​​and ABAP, C / C ++, C #, COBOL, CSS, Erlang, Flex / ActionScript, Groovy, Java, JavaScript, JSON, Objective-C, PHP, PL / I, PL / SQL, Puppet, Python, role play, Swift, VB.NET, Visual Basic 6, and XML. One of the most impressive features is his Scalability. It’s easy to cover new languages ​​and add rules engines with extensions Plugin-shaped mechanisms.

Installation steps in windows machine:

1. Download Sonar from http://www.sonarqube.org/downloads/

Install SonarQube in windows- downloading

2. After downloading, extract the zip file and go to the bin / StartSonar.bat extraction path Based on the operating system, it should be started when using StartSonar.sh on a Linux computer.

Install SonarQube in windows-extraction

3. Once the Sonar server is up and running, use the URL to access the Sonar server dashboard.
http: // localhost: 9000 / or http: //: 9000 /

Install SonarQube in windows

4. Log in to the Sonar dashboard with your default username and password. The default username and password are admin / admin.

Install SonarQube in windows

5. If you want to integrate with Jenkins, you need to create a security token via Sonar
Dashboard. Go to Administration –> My Account –> Security –> enter a name for Token –> Generate a token.

Security Token
Administration
Note : New token “Petclinic” has been created. Make sure you copy it now, you won’t
be able to see it again!
–> take backup of the token using any notepad.

6. Check the updated token list goto Administration –> select security –> Users.

Security
Security Updation

7. Once Handy is able to use security tokens, it will be able to integrate with Jenkins.

8. Go to the Jenkins dashboard Jenkins Home –> Manage Jenkins –> Manage Plugins –>
Available tabs –> Select Search in Install SonarQube Scanner Plugin without rebooting.

9. After successful installation of the plugin, you need to configure the sonar server properties. Go to jenkins home –> Manage Jenkins –> Configure your system –> SonarQube server and add the appropriate properties.

Server

10. And we need to configure the SonarQube Scanner installation tool in Jenkins –> Global
tool configurations –> SonarQube Scanner

Configuration

11. Once all sonar-related installation and configuration is complete, you need to do this
Add a build step to run the SonarQube scanner. Use these steps to run your build job.

Steps to Run Build Job:

Sonar-project.properties are required to configure sonar for a particular application. In The sample application sonar-project.properties file is already available, as shown here:

# Required metadata
sonar.projectKey=java-sonar-runner-simple
sonar.projectName=Simple Java project analyzed with the
SonarQube Runner
sonar.projectVersion=1.0
# Comma-separated paths to directories with sources (required)
sonar.sources=src
# Language
sonar.language=java
# Encoding of the source files
sonar.sourceEncoding=UTF-8

15. In the build selector, go to Jenkins job configuration and select Run SonarQube
scanner. Add the appropriate properties and save. After saving, build the job.

Execution
Execution

Verify the console output of a building job for Sonar execution

[PetClinic] $
C:\Users\Madhu\.jenkins\tools\hudson.plugins.sonar.SonarRunnerInstallation\
SonarQube_Scanner\bin\sonar-scanner.bat -e -
Dsonar.host.url=http://localhost:9000/ ******** -Dsonar.language=java "-
Dsonar.projectName=Simple Java project analyzed with the SonarQube Runner"
-Dsonar.projectVersion=1.0 -Dsonar.sourceEncoding=UTF-8 -
Dsonar.projectKey=java-sonar-runner-simple -Dsonar.sources=src -
Dsonar.projectBaseDir=C:\Users\Madhu\.jenkins\workspace\PetClinic
C:\Users\Madhu\.jenkins\tools\hudson.plugins.sonar.SonarRunnerInstallation\
SonarQube_Scanner\bin\..
INFO: Option -e/--errors is no longer supported and will be ignored
INFO: Scanner configuration file:
C:\Users\Madhu\.jenkins\tools\hudson.plugins.sonar.SonarRunnerInstallation\
SonarQube_Scanner\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file:
C:\Users\Madhu\.jenkins\workspace\PetClinic\sonar-project.properties
INFO: SonarQube Scanner 2.8
INFO: Java 1.8.0_91 Oracle Corporation (64-bit)
INFO: Windows 8.1 6.3 amd64
INFO: User cache: C:\Users\Madhu\.sonar\cache
INFO: Load global repositories
INFO: Load global repositories (done) | time=948ms
INFO: User cache: C:\Users\Madhu\.sonar\cache
INFO: Load plugins index
INFO: Load plugins index (done) | time=63ms
INFO: SonarQube server 6.2
INFO: Default locale: "en_IN", source code encoding: "UTF-8"
INFO: Process project properties
INFO: Load project repositories
INFO: Load project repositories (done) | time=140ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=185ms
INFO: Load active rules
INFO: Load active rules (done) | time=1860ms
INFO: Publish mode
INFO: ------------- Scan Simple Java project analyzed with the SonarQube
Runner
INFO: Language is forced to java
INFO: Load server rules
INFO: Load server rules (done) | time=359ms
INFO: Initializer GenericCoverageSensor
INFO: Initializer GenericCoverageSensor (done) | time=0ms
INFO: Base dir: C:\Users\Madhu\.jenkins\workspace\PetClinic
INFO: Working dir: C:\Users\Madhu\.jenkins\workspace\PetClinic\.sonar
INFO: Source paths: src
INFO: Source encoding: UTF-8, default locale: en_IN
INFO: Index files
INFO: 36 files indexed
INFO: Quality profile for java: Sonar way
INFO: Sensor Lines Sensor
INFO: Sensor Lines Sensor (done) | time=31ms
INFO: Sensor JavaSquidSensor
INFO: Configured Java source version (sonar.java.source): none
INFO: JavaClasspath initialization
WARN: Bytecode of dependencies was not provided for analysis of source
files, you might end up with less precise results. Bytecode can be provided
using sonar.java.libraries property
INFO: JavaClasspath initialization (done) | time=0ms
INFO: JavaTestClasspath initialization
INFO: JavaTestClasspath initialization (done) | time=0ms
INFO: Java Main Files AST scan
INFO: 36 source files to be analyzed
WARN: Metric 'lines' is an internal metric computed by SonarQube. Provided
value is ignored.
INFO: Java Main Files AST scan (done) | time=9459ms
INFO: Java Test Files AST scan
INFO: 36/36 source files have been analyzed
INFO: 0 source files to be analyzed
INFO: Java Test Files AST scan (done) | time=0ms
INFO: Sensor JavaSquidSensor (done) | time=12102ms
INFO: Sensor SCM Sensor
INFO: SCM provider for this project is: git
INFO: 0/0 source files have been analyzed
INFO: 36 files to be analyzed
INFO: 36/36 files analyzed
INFO: Sensor SCM Sensor (done) | time=3228ms
INFO: Sensor Coverage Report Import
INFO: Sensor Coverage Report Import (done) | time=0ms
INFO: Sensor Coverage Report Import
INFO: Sensor Coverage Report Import (done) | time=0ms
INFO: Sensor Unit Test Results Import
INFO: Sensor Unit Test Results Import (done) | time=0ms
INFO: Sensor SurefireSensor

INFO: parsing C:\Users\Madhu\.jenkins\workspace\PetClinic\target\surefire-
reports

WARN: Resource not found:
org.springframework.samples.petclinic.system.ProductionConfigurationTests
INFO: Sensor SurefireSensor (done) | time=379ms
INFO: Sensor JaCoCoSensor
INFO: No JaCoCo analysis of project coverage can be done since there is no
class files.
INFO: Sensor JaCoCoSensor (done) | time=32ms
INFO: Sensor JaCoCoItSensor
INFO: JaCoCoItSensor: JaCoCo IT report not found:
C:\Users\Madhu\.jenkins\workspace\PetClinic\target\jacoco-it.exec
INFO: Sensor JaCoCoItSensor (done) | time=0ms
INFO: Sensor JaCoCoOverallSensor
INFO: Analysing
C:\Users\Madhu\.jenkins\workspace\PetClinic\target\jacoco.exec
INFO: No JaCoCo analysis of project coverage can be done since there is no
class files.
INFO: Sensor JaCoCoOverallSensor (done) | time=168ms
INFO: Sensor XmlFileSensor
INFO: Sensor XmlFileSensor (done) | time=0ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=156ms
INFO: Sensor Code Colorizer Sensor
INFO: Sensor Code Colorizer Sensor (done) | time=31ms
INFO: Sensor CPD Block Indexer
INFO: JavaCpdBlockIndexer is used for java
INFO: Sensor CPD Block Indexer (done) | time=233ms
INFO: Calculating CPD for 21 files
INFO: CPD calculation finished
INFO: Analysis report generated in 531ms, dir size=188 KB
INFO: Analysis reports compressed in 522ms, zip size=124 KB
INFO: Analysis report uploaded in 1345ms
INFO: ANALYSIS SUCCESSFUL, you can browse
http://localhost:9000/dashboard/index/java-sonar-runner-simple
INFO: Note that you will be able to access the updated dashboard once the
server has processed the submitted analysis report
INFO: More about the report processing at
http://localhost:9000/api/ce/task?id=AWdFU3NgfYj6U_V0n-4B
INFO: Task total time: 32.281 s
INFO: ---------------------------------------------------------------------
---
INFO: EXECUTION SUCCESS
INFO: ---------------------------------------------------------------------
---
INFO: Total time: 43.270s
INFO: Final Memory: 49M/332M
INFO: ---------------------------------------------------------------------
---
Recording test results
No emails were triggered.
Finished: SUCCESS

Let’s check the sonar dashboard for static code analysis results.
http://localhost:9000/dashboard/index/java-sonar-runner-simple
In the PROJECTS section, we can find project details available now. Click on the project name:

Install SonarQube in windows - exploration
SonarQube execution
Analization