After installing Jenkins, we will now see how to interface it with our SonarQube environment.
If you have not been following along this series about creating an environment of code analysis with SonarQube, here are the items we need today:
- Installing a Java JDK.
- The installation of SonarQube.
- And the previous post about the installation of Jenkins.
You can also have a look at the documentation about configuring the SonarQube Jenkins Plugin, on the SonarSource website.
Download and install the plugin SonarQube Jenkins
Let’s start by launching Jenkins, the web application of the same name under Tomcat, located at http://localhost:8888/jenkins in my environment.
In the Administration page of Jenkins, activate the menu to manage plugins:
On the next page, select the tab for all the available plugins:
Search and select the SonarQube plugin. I suggest you do a search on the string ‘Sonar’ to quickly find the plugin in this particularly long list.
At the bottom of the page, click the button ‘Install without restart’: Jenkins starts the installation and once it is finished…
… tells us that the SonarQube plugin has been updated. We can return to the Administration page of Jenkins to select the setup menu, which will allow us to set our SonarQube installation.
Configuring the SonarQube Runner
Jenkins will use the SonarQube Runner (that we have installed previously) to run analysis of code.
In order to configure it, we return to the Administration page of Jenkins to activate the menu of configuration.
Notice in this page the first line indicating the working directory of Jenkins, that we have configured in the previous post.
Then, Jenkins proposes us to configure or even install a JDK.
This is not necessary if you have proceeded as indicated during the installation of a Java JDK, creating a JAVA_HOME variable and declaring in the path of your PC, the directory containing the java executables (%JAVA_HOME%\bin).
Below, a section devoted to the SonarQube Runner will allow us to configure it. First, click the button to add an instance of SonarQube Runner.
This will open a section to enter its configuration:
In this section:
- Uncheck the automatic installation option.
- Enter a name for you SonarQube Runner instance.
- Enter its localisation.
And finally, do not forget to save your settings. It’s done.
Configuring SonarQube
The configuration of SonarQube into Jenkins will follow the same logic. In this same configuration page of the ‘Jenkins system’, locate the section dedicated to SonarQube:
Again, click the button to create a new SonarQube instance.
Jenkins then asks to enter a name to identify this SonarQube installation.
Now, you can activate the button ‘Advanced…’ (‘Avanzado…’ in my interface) to open a page that will allow us to enter the different configuration settings.
These are the same as those listed in our ‘sonar-properties’ file, to configure SonarQube. So just open this file to use the same parameters:
We indicate:
- The url of our SonarQube web application.
- The access to our database.
- The JDBC driver.
I mentioned also the Oracle user and password to access the SonarQube schema (even if I actually used the default values). I did not include a SonarQube user to perform the analyzes, since I had not done it either during the installation of the SonarQube Runner.
Don’t forget to save your settings with the button located at the end of the page.
Et voilà. Now we can use Jenkins to create and run SonarQube analysis.
This will be the subject of our next post. Very soon.
This post is also available in Leer este articulo en castellano and Lire cet article en français.