Jenkins With SonarQube#
Introduction#
- In this section, we will try to integrate
SonarQube
intoJenkins pipeline
for checking the quality of Spring Boot project when there are new commits. - If you have not known about Jenkins, SonarQube or how to integrate your Spring Boot project with SonarQube. I will recommend read posts below:
SonarQube Configuration#
- Firstly, you should access
Sonarqube server
. Then go toAdministration
-->Security
-->Permission Template
and check the checkbox forExecute Analysis
for yourSonarqube
account that you will use on Jenkins. - So for this configuration, the user will have permission to execute sonar analysis when we use this user on Jenkins Server.
- Next you go to
My Account
-->Security
and generate aToken
as below. So this Token will be used for accessing SonarQube Server instead of using username/password.
- You can try this token by replacing the
username/password
inpom.xml
of your Spring Boot project.
pom.xml | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
- Next, you should go to
Administration
->Configuration
->WebHooks
and clickCreate
button. Then add some information asName
andURL
. - Note: the
URL
has format like{JENKINS SERVER}/sonarqube-webhook/
. For exmaple: your Jenkins Server is running athttp://192.168.1.18:8081
so theURL
should behttp://192.168.1.18:8081/sonarqube-webhook/
. - Note: On Jenkins Server we have to add plugin
Sonarqube Scanner
which will do in the StepJENKINS CONFIGURATION
below, then theURL
above will be available.
Jenkins Configuration#
- First, let’s go to
Manage Jenkins
->Manage Plugins
-> Then choose tagAvailable
and findSonarQube Scanner
-> then clickInstall
- Next, go to the
Manage Jenkins
->Global Tool Configuration
-> scroll down to tagSonarQube Scanner
and fill some information as below:
- Next, go to
Manage Jenkins
->Configure System
-> scroll down to tagSonarQube servers
and fill some information asName
,URL of sonarqube server
.
- Then at step
Server authentication token
, let's choose buttonAdd
to add theSonarQube Token
- Let's choose
Secret Text
, put yourSonarQube Token
, add a description and clickadd
button.
- Now, at step
Server authentication token
you can choose yourSonarQube Token
as the image below.
- Finally, let's create/update your
Jenkinsfile
in your project as below.
build.Jenkinsfile | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
Testing#
- Finally, commit and push the
Jenkinfile
in your repository then go to Jenkins server to check the build result.
- So, that’s it. Thanks and Good luck!