| ... | ... | @@ -54,4 +54,68 @@ In Gitlab you need to create a Webhook for Jenkins. Go to Project Settings > Int |
|
|
|
Created Webhook.
|
|
|
|
Test the connection. I tested the connection using Push events. You may need to [enable same network-traffic](https://docs.gitlab.com/ee/security/webhooks.html). You should see a success message in GitLab.
|
|
|
|
|
|
|
|
### Sonarqube
|
|
|
|
#### Installing Sonarqube
|
|
|
|
I used Docker-compose to install sonarqube:
|
|
|
|
```
|
|
|
|
sonarqube:
|
|
|
|
image: 'sonarqube:lts'
|
|
|
|
ports:
|
|
|
|
- 9000:9000
|
|
|
|
- 9092:9092
|
|
|
|
container_name: sonarqube
|
|
|
|
|
|
|
|
```
|
|
|
|
You should be able to access your sonarqube on port 9000.
|
|
|
|
|
|
|
|
#### Configuring Sonarqube to work with Jenkins
|
|
|
|
|
|
|
|
You need to create a project in Sonarqube. Log in to Sonarqube the default login is admin/admin. You can create a project in Administrator > Projects > Projects Management > Create Project.
|
|
|
|
Add a name to your project and a key which Jenkins will use to connect to Sonarqube. I named mine dev and set the key to dev2.
|
|
|
|

|
|
|
|

|
|
|
|
Create project.
|
|
|
|
|
|
|
|
On Jenkins go to Manage Jenkins > Manage Plugins and install SonarQube Scanner for Jenkins:
|
|
|
|

|
|
|
|
Sonarqube scanner.
|
|
|
|
|
|
|
|
You need to restart Jenkins.
|
|
|
|
After that go to Manage Jenkins > Global Tool Configuration > SonarQube Scanner :
|
|
|
|

|
|
|
|
You need to set a name to your sonarqube scanner and how it is installed to Jenkins I selected the default Maven.
|
|
|
|
|
|
|
|
You should also set Maven installation:
|
|
|
|

|
|
|
|
Maven installation.
|
|
|
|
|
|
|
|
Go Back to Manage Jenkins and go to Configure System:
|
|
|
|
Add SonarQube server:
|
|
|
|

|
|
|
|
|
|
|
|
Add a name to your server-connection and your url. You also should create a token for your connection. For this go to Sonarqube and Administrator > My Account > Security :
|
|
|
|
Generate a new token and name your token. You should also save it to secure location because you won't be able to access it from here again.
|
|
|
|

|
|
|
|
Created token.
|
|
|
|
|
|
|
|
Now to integrate the sonarqube to the GitLab project we need to go to the Jenkins project where we added the GitLab connection and go to Configure > Build :
|
|
|
|
|
|
|
|

|
|
|
|
Add analysis properties to match your SonarQube: Now add the project name, key and the version of Sonarqube you are running. You can also enter the project version. Save the settings.
|
|
|
|
|
|
|
|
Now you should be able to build your project using Jenkins:
|
|
|
|

|
|
|
|
|
|
|
|
You can see the builds in the build history. You can view the build selecting it from the build history:
|
|
|
|
|
|
|
|
My output looked like this:
|
|
|
|

|
|
|
|
Console output.
|
|
|
|
|
|
|
|
You can also view the sonarqube scan:
|
|
|
|

|
|
|
|
Link to Sonarqube scan.
|
|
|
|
|
|
|
|
Now you can see the full results of the scan:
|
|
|
|

|
|
|
|
Sonarqube scan. |
|
|
\ No newline at end of file |