| ... | ... | @@ -40,6 +40,54 @@ Then you need to set the project specific token and the GitLab url. These can be |
|
|
|
Copy the token to setup the runner.
|
|
|
|

|
|
|
|
|
|
|
|
Now we can set up the project settings for Sonarqube.
|
|
|
|
|
|
|
|
#### Setting up .gitlab-ci.yml
|
|
|
|
|
|
|
|
Now to get sonarqube test your project code we need to set the .gitlab-ci.yml file:
|
|
|
|
|
|
|
|
```
|
|
|
|
stages:
|
|
|
|
- analysis
|
|
|
|
|
|
|
|
sonarqube:
|
|
|
|
stage: analysis
|
|
|
|
image: ciricihq/gitlab-sonar-scanner
|
|
|
|
variables:
|
|
|
|
SONAR_URL: http://sonar-url
|
|
|
|
SONAR_ANALYSIS_MODE: preview
|
|
|
|
script:
|
|
|
|
- gitlab-sonar-scanner -Dsonar.host.url=http://172.20.2.132:9000 -Dsonar.projectKey=projectkey -Dsonar.login=username -Dsonar.password=password -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.commit_sha=$CI_COMMIT_REF -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
|
|
|
|
|
|
|
|
sonarqube-reports:
|
|
|
|
stage: analysis
|
|
|
|
image: ciricihq/gitlab-sonar-scanner
|
|
|
|
variables:
|
|
|
|
SONAR_URL: http://sonar-url
|
|
|
|
SONAR_ANALYSIS_MODE: publish
|
|
|
|
script:
|
|
|
|
- gitlab-sonar-scanner -Dsonar.host.url=http://sonar-url -Dsonar.projectKey=projectkey -Dsonar.login=username -Dsonar.password=password -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.commit_sha=$CI_COMMIT_REF -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
You need to set your Sonarqube-server url and login credentials for the scanner to access it. I used [gitlab-sonar-scanner](https://github.com/ciricihq/gitlab-sonar-scanner) container. We also need to set sonar-project.properties file to the project root directory:
|
|
|
|

|
|
|
|
|
|
|
|
In sonar-project.properties:
|
|
|
|
```
|
|
|
|
# must be unique in a given SonarQube instance
|
|
|
|
sonar.projectKey=projectkey
|
|
|
|
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
|
|
|
|
sonar.projectName=projectname
|
|
|
|
sonar.projectVersion=1.0
|
|
|
|
|
|
|
|
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
|
|
|
|
# This property is optional if sonar.modules is set.
|
|
|
|
sonar.sources=.
|
|
|
|
|
|
|
|
# Encoding of the source code. Default is default system encoding
|
|
|
|
#sonar.sourceEncoding=UTF-8
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|