SonarQube
Introduction to SonarQube
SonarQube is a service which provides static code analysis for your Continuous Delivery project. It runs on Java and integrates with multiple Continuous Delivery services like Jenkins. The SonarQube dashboard is accessible via an http webpage which can be accessed from either your own network of via the internet when desired, depending on how you set up your SonarQube server. SonarQube can inspect more than 20+ programming language, like JavaScript, C/C++, Python, et cetera. It can show trends and graphs displaying the evolution of the size of your code base, test coverage, bugs and many more things over time.
Installation
The official SonarQube website contains a detailed overview of how to set up SonarQube. Because there are many options to choose from it might get complicated fairly quickly. Therefore a summary is posted below explaining how SonarQube has been installed on the HAN-AR test automation server. To give SonarQube a quick try, it's possible to set up SonarQube in 2 minutes via this link.
Download and Install:
First go to [https://docs.sonarqube.org/display/SONAR/Setup+and+Upgrade%7C this page and have a look at the section "Install a production instance". It contains two links. Please read the system requirements first before commencing with the actual SonarQube installation.
Run:
In Command Prompt go to the map where SonarQube is installed and start the service, for example:
C:\Program Files\SonarQube\sonarqube-5.6.6\bin\windows-x86-64>StartSonar.bat
If the service is up, SonarQube is installed properly.
This can be checked by the following link: SonarQube.
On the picture below, on the left side of the screen it shows that the SonarQube server is successfully started.
For SonarQube Scanner:
The following link can be used to install SonarQube Scanner: SonarQube Scanner.
To download SonarQube Scanner click on "Windows 64 bit" and the download will start after clicking on "Ok".
Configuration
For SonarQube:
To log in the first time in the SonarQube server, for "Login" type admin and for "password" type also admin, as show in the picture below.
Now the password can be changed and the token can be made, by clicking on the log in name in the upper right corner (see picture below) and click on "My account".
Then go to "Security" and now the password can be changed (see picture above). After that, the token can be made by typing a name in block "Enter Token Name" and then click on Generate. Then there will be a code that must be copied and pasted in "Server authentication token" in Jenkins, in the configuration of SonarQube server. An example of the SonarQube token (with the code) can be seen in the picture below.
To change the default port, under the header "WEB SERVER" in the file "sonar.properties" in the map of SonarQube, the # must be removed and now the "sonar.web.port" can be changed, for example to 5900.
Next go to the homepage of the SonarQube server and click on "Administration".
Now the "CI server" needs to be filled in, this is the continuous integration server URL. Then the "SCM server" needs to be filled in. Here the URL of the repository needs to be filled in, an example can be seen in the picture below.
Now going further with the configuration by clicking on "Java". By "File suffixes" type in .java.
The configuration of SonarQube is now done.
For SonarQube Scanner:
To configure the settings of SonarQube Scanner follow the steps by using this link. These settings must be filled in the project settings in Jenkins (see "Execute SonarQube Scanner").