SonarQube Jenkins integration:

ajay lakshmandas
3 min readMay 11, 2023

--

Prerequisites:

a. Jenkins
b. SonarQube scanner

  1. click on “Manage Jenkins” > “Manage Plugins” > Click on the “Available tab” then search for SonarQube.

2. Select “SonarQube Scanner

Generate token in SonarQube server:

3. A new “Tokens” area will appear. Under “Generate Tokens“, put a name you like then hit “Generate“.

4. While still logged into Jenkins as an administrator go to “Manage Jenkins” > “Configure System“.

Scroll down to the SonarQube configuration section, click Add SonarQube, and add the values you need to provide.

5.SonarQube server URL, that is where your SonarQube server is running at then the “Server authentication token“. For the Server authentication token, click on “Add” then “Jenkins” as shown below.
6.we need to configure SonarQube scanner. “Manage Jenkins” then click on “Global configuration Tool“. Scroll down and look for “SonarQube Scanner“. Click on “Add SonarQube Scanner” tab so that we can add it here.

Create a project in SonarQube:

in SonarQube Server, log in as Administrator and create a project by following the following steps. Click on “Administration” > “Projects“. Click on the “Projects” drop down list and click on “Management“. On your far right, close to the top, you will see a tab called “Create Project“.

Click on it and it will bring a form where you will enter the details of your project, that is its name and key. Your key in any value here as you prefer then to click on “Create “.

The is testing it out with sample code. I will use code written in python

The stage we will use for this in our pipeline is shared below.

On the snippet, the installationName is the name you gave when you were configuring your SonarQube Server in Jenkins and credentialsId is the Name/ID of the token we added when we were integrating SonarQube and Jenkins

Now the reports will be shared in SonarQube server we can be able to access it by using port number or by following the link Wich is given in output

Generated Report:

--

--

No responses yet