| ... | @@ -12,10 +12,18 @@ |
... | @@ -12,10 +12,18 @@ |
|
|
### SonarQube
|
|
### SonarQube
|
|
|
- OS: Ubuntu 18.04 LTS 64bit
|
|
- OS: Ubuntu 18.04 LTS 64bit
|
|
|
- CPU: Intel Core 2 Duo Processor E7400 2.80GHz
|
|
- CPU: Intel Core 2 Duo Processor E7400 2.80GHz
|
|
|
- RAM: 4GB 800MHz
|
|
- RAM: 4Gb 800MHz
|
|
|
- GPU: Redwood XT Radeon HD [5670/5690/5730] AMD/ATI
|
|
- GPU: Redwood XT Radeon HD [5670/5690/5730] AMD/ATI
|
|
|
- MB: Asus P5KPL-CM
|
|
- MB: Asus P5KPL-CM
|
|
|
|
|
|
|
|
|
## Specification in Guide
|
|
|
|
- OS: Windows 10 Pro 64bit
|
|
|
|
- CPU: Intel i5-7600 3.50GHz
|
|
|
|
- RAM: 16Gb 2400MHz
|
|
|
|
- GPU: Intel HD Graphics 630
|
|
|
|
|
|
|
|
- VM's OS: Ubuntu 18.04 LTS 64bit
|
|
|
|
|
|
|
## Why CI and why GitLab Runner on Windows 10?
|
|
## Why CI and why GitLab Runner on Windows 10?
|
|
|
- Continuous integration (CI) helps to keep information about the status of the project in code level. With CI we perform unit tests and code quality assurance.
|
|
- Continuous integration (CI) helps to keep information about the status of the project in code level. With CI we perform unit tests and code quality assurance.
|
|
|
- Windows 10 simply because we can do the necessary analyzes for the C# projects. Other operating systems did not support .NET 4.5 builds.
|
|
- Windows 10 simply because we can do the necessary analyzes for the C# projects. Other operating systems did not support .NET 4.5 builds.
|
| ... | @@ -484,8 +492,59 @@ gitlab-runner.exe restart |
... | @@ -484,8 +492,59 @@ gitlab-runner.exe restart |
|
|
- Add new variable name "USER_TOKEN" and go to your GitLab's user settings -> Acces Tokens
|
|
- Add new variable name "USER_TOKEN" and go to your GitLab's user settings -> Acces Tokens
|
|
|
- Give name for token, name it as "sonar", give expire date as long as you want and lastly check all "Scopes"
|
|
- Give name for token, name it as "sonar", give expire date as long as you want and lastly check all "Scopes"
|
|
|
- Click "Create personal access token" and copy Access Token and add it to "USER_TOKEN" in CI/CD Variables settings
|
|
- Click "Create personal access token" and copy Access Token and add it to "USER_TOKEN" in CI/CD Variables settings
|
|
|
- Now save variables and
|
|
- Now save variables and let's edit **.gitlab-ci.yml** file
|
|
|
|
- In .yml file we need to create another job for analyze project as in issue mode, so all errors are commented in latest commit.
|
|
|
|
- Open from your local project's folder .yml file
|
|
|
|
- Name job like "issuemode_scan:"
|
|
|
|
- Add **tags:*** to activate right runner
|
|
|
|
- As a parameter give tag you gave for runner, I'll use "scan"
|
|
|
|
- Add **stage:** and it's parameter we will use previous one what we have used "scanning"
|
|
|
|
- Add **script:**, we only have to add one line but to sonar-scanner will have many parameters to do what we want.
|
|
|
|
- So we start script by calling sonar-scanner.bat
|
|
|
|
- After that we add **-Dsonar.login=%SONAR_LOGIN%** and SONAR_LOGIN variables comes from GitLab
|
|
|
|
- Next we want to change analysis mode so we add **-Dsonar.analysis.mode=preview**
|
|
|
|
- Now plugin needs to know what is commit's SHA so we add **-Dsonar.gitlab.commit_sha=%CI_COMMIT_SHA%**
|
|
|
|
- Also we will tell reference of the commit **-Dsonar.gitlab.ref_name=%CI_COMMIT_REF_NAME%**
|
|
|
|
- Let's identify project where the analysis is happening by **-Dsonar.gitlab.project_id=%CI_PROJECT_ID%**
|
|
|
|
- Also we need to identify the user who has made the latest commit by **-Dsonar.gitlab.user_token=%USER_TOKEN%**
|
|
|
|
- Now we add last line and it is **allow_failure: true**
|
|
|
|
- Save file and now it should look like this
|
|
|
|
|
|
|
|
```YAML
|
|
|
|
stages:
|
|
|
|
- scanning
|
|
|
|
running_scan:
|
|
|
|
tags:
|
|
|
|
- scan
|
|
|
|
stage: scanning
|
|
|
|
script:
|
|
|
|
- call npm i -s
|
|
|
|
- call jest --coverage
|
|
|
|
- sonar-scanner.bat
|
|
|
|
allow_failure: true
|
|
|
|
|
|
|
|
issuemode_scan:
|
|
|
|
tags:
|
|
|
|
- scan
|
|
|
|
stage: scanning
|
|
|
|
script:
|
|
|
|
- sonar-scanner.bat -Dsonar.login=%SONAR_LOGIN% -Dsonar.analysis.mode=preview -Dsonar.gitlab.commit_sha=%CI_COMMIT_SHA% -Dsonar.gitlab.ref_name=%CI_COMMIT_REF_NAME% -Dsonar.gitlab.project_id=%CI_PROJECT_ID% -Dsonar.gitlab.user_token=%USER_TOKEN%
|
|
|
|
allow_failure: true
|
|
|
|
```
|
|
|
|
|
|
|
|
- Now you only need to push latest changes to GitLab and see the result of GitLab's and SonarQube's collaboration
|
|
|
|
- If code has errors or bugs SonarQube will report them in to latest commit by commenting to it.
|
|
|
|
- Guide didn't have any errors now but you can always go and change the code and make bug and bad code to see it
|
|
|
|
- SonarQube will add to pipeline "External" stage with "sonarqube" job and job's mission is to make that comment to commit if there are something to report about
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
- Guide's "running_scan" job did fail because our database was disconnected and unit tests can't be tested without database
|
|
|
|
- But here was full guide to make CI-environment to analyze GitLab project's with SonarQube and with one PC
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Author
|
|
|
|
- Joona Hautamäki
|
|
|
|
- IoTitude
|
|
|
|
- 30.7.2018
|
|
|
|
|
|