export PORT=9090
export APP_NAME=sonarqube-to-gitlab-webhook
export LOG_LEVEL=INFO
You need to configure these for local tests or real deployment.
Configure these environment variables:
- GITLAB_URL : Gitlab URL. Example: https://gitlab.domain
- SONARQUBE_SECRET : Secret created in Webhook in Sonarqube configuration. Example: LONGHASH
- GITLAB_TOKEN : Gitlab Personal Token with api access.
The project is using Go Modules for dependency management Module: github.com/betorvs/sonarqube-to-gitlab-webhook
Run the tests
TESTRUN=true go test ./... -coverprofile=cover.out
go tool cover -html=cover.out
Install golangci-lint and run lint:
golangci-lint run
docker build .
kubectl create ns sonarqube-webhook
kubectl create secret generic sonarqube-webhook --from-literal=sonarqubeSecret=LONGHASH --from-literal=gitlabToken=xxx-9X-zxczxczxczxc -n sonarqube-webhook --dry-run=client -o yaml > sonarqube-secret.yaml
kubectl apply -f sonarqube-secret.yaml
kubectl apply -f deployment.yaml
Creates a step inside your .gitlab-ci.yml
:
services:
- docker:18.09.7-dind
stages:
- test
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
variables:
SONAR_HOST_URL: "https://sonar.example.local"
GIT_DEPTH: 0
sonarqube-check:
stage: test
script:
- sonar-scanner -Dsonar.qualitygate.wait=true
allow_failure: true
sonar.projectKey=projectGroup/projectName
sonar.analysis.disabledGitlabPost=false
sonar.analysis.disabledQualityReport=true
Use sonar.analysis.disabledGitlabPost
equal true
to disable post in GitLab.
Use sonar.analysis.disabledQualityReport
equal true
to remove full quality report (it will print only Quality Gateway Name and Quality Gateway Status)
Add this configuration in sonar-propject.properties:
sonar.analysis.projectID="10"
Commit example in gitlab.com
URL: Report Link
- Name: TEST
- Status: OK
- Operator: GREATER_THAN
- Value: 1
- Error Threshold: 1
- Status: OK 👍
- Operator: GREATER_THAN
- Value: 1
- Error Threshold: 1
- Status: OK 👍
- Operator: GREATER_THAN
- Value: 1
- Error Threshold: 1
- Status: OK 👍
- Operator: LESS_THAN
- Value: 0.0
- Error Threshold: 70
- Status: OK 👍
- Operator: GREATER_THAN
- Value: 0.0
- Error Threshold: 3
- Status: OK 👍
The project was initialized using Golang Spell.
The Architectural Model adopted to structure the application is based on The Clean Architecture. Further details can be found here: The Clean Architecture and in the Clean Architecture Book.