| ... | @@ -246,14 +246,69 @@ Started SonarQube. |
... | @@ -246,14 +246,69 @@ Started SonarQube. |
|
|
|
|
|
|
|
```shell
|
|
```shell
|
|
|
#----- Default SonarQube server
|
|
#----- Default SonarQube server
|
|
|
sonar.host.url=<virtual machine's ip-adress>:9000
|
|
sonar.host.url=http://<virtual machine's ip-adress>:9000
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
- Now SonarScanner is ready to use but we still need to do few steps
|
|
- Now SonarScanner is ready to use but we still need to do few steps
|
|
|
|
|
|
|
|
|
### Step 5: Setting project ready for first scan
|
|
|
|
|
|
|
|
|
- To analyze project it needs .gitlab-ci.yml and sonar-project.properties files
|
|
|
|
- But first we need to make project on SonarQube
|
|
|
|
- Connect to your SonarQube < virtual machine's ip-address >:9000
|
|
|
|
- Login with System Administrator credentials (admin/admin)
|
|
|
|
- Go Administration -> Projects -> Management -> Create Project
|
|
|
|
- For example name it as CI-testing and as project key use testing
|
|
|
|
- Visibility: public
|
|
|
|
- Click create
|
|
|
|
- Now you have empty project in SonarQube what is waiting for first scan
|
|
|
|
- Go and make new sonar-project.properties file in root of project, the one we downloaded begin of guide
|
|
|
|
- sonar-project.properties file tells SonarScanner what is it scanning, which name project has, what is it project's key and what is project's version number
|
|
|
|
|
|
|
|
|
sonar-project.properties
|
|
|
|
---
|
|
|
|
|
|
|
|
|
```
|
|
|
|
# must be unique in a given SonarQube instance
|
|
|
|
sonar.projectKey=testing
|
|
|
|
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
|
|
|
|
sonar.projectName=CI-testing
|
|
|
|
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
|
|
|
|
```
|
|
|
|
|
|
|
|
- Now if we'd run sonar-scanner.bat in cmd project's directory it would analyzes project
|
|
|
|
- But we'd like to scan with Gitlab runner and everytime we push something to Gitlab
|
|
|
|
- Next we need to make .gitlab-ci.yml to same place where we made sonar-project.properties file
|
|
|
|
- You can read more about Gitlab's .yml file from [here](https://docs.gitlab.com/ee/ci/yaml/)
|
|
|
|
- In .yml don't use TAB for spacing, use only space
|
|
|
|
- Firstly runner needs to now about it's job stages, are there many or is it just single stage job so we start writing file from ***stages:***
|
|
|
|
- Let's add for it one stage and name it as ***- scanning***
|
|
|
|
- Next we need to define job's name as like ***running_scan:***
|
|
|
|
- Now **job** needs ***tags:*** to wake up right Gitlab runner
|
|
|
|
- Under ***tags:*** add one tag what you made in Gitlab runner's registration (guide will use scan)
|
|
|
|
- Then job will need to know which stage it belongs so we add ***stage: scanning***
|
|
|
|
- It won't be a job if we don't tell to Runner what to do so we add ***script***
|
|
|
|
- Only thing Runner now needs to do is scan the project with SonarScanner so we add under the script is ***- sonarscanner.bat***
|
|
|
|
- shell command will be executed in root of project folder
|
|
|
|
- And that is all we need for now, your .gitlab-ci.yml should look like this now
|
|
|
|
|
|
|
|
```YAML
|
|
|
|
stages:
|
|
|
|
- scanning
|
|
|
|
running_scan:
|
|
|
|
tags:
|
|
|
|
- scan
|
|
|
|
stage: scanning
|
|
|
|
script:
|
|
|
|
- sonar-scanner.bat
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| ... | |
... | |
| ... | | ... | |