QA这块,在ci/cd中,还是不可或缺的。之前少涉及,现在慢慢补上。
SonarQube的简单安装:
https://www.jianshu.com/p/c0f6f069b203
一,定义sonar-project.properties文件
sonar.host.url=http://192.168.1.212:19000
sonar.sourceEncoding=UTF-8
sonar.login=admin
sonar.password=password
sonar.projectKey=go-demo
sonar.projectName=go-demo
sonar.projectVersion=1.0
sonar.golint.reportPath=report.xml
sonar.coverage.reportPath=coverage.xml
sonar.coverage.dtdVerification=false
sonar.test.reportPath=test.xml
sonar.sources=./main/
sonar.sources.inclusiOns=**/**.go
sonar.sources.exclusiOns=**/**_test.go,**/vendor/*.com/** ,**/vendor/*.org/**, **/vendor/**
sonar.tests=./main/
sonar.test.inclusiOns=**/**_test.go
sonar.test.exclusiOns=**/vendor/*.com/**,**/vendor/*.org/**,**/vendor/**
docker pull sonarsource/sonar-scanner-cli:latest
四,重新定义.gitlab-ci.yml文件
stages:
- test
- package
- release
sonarqube-test:
image: sonarsource/sonar-scanner-cli:latest
stage: test
only:
- triggers
tags:
- runInDocker
script:
- sonar-scanner
go_package:
image: golang
stage: package
only:
- triggers
tags:
- runInDocker
script:
- echo ${APP_NAME}
- echo ${RELEASE}
- echo ${BUILD_SCRIPT}
- echo ${DEPLOY_SCRIPT}
- echo ${FILE_UP_SERVER}
- go version
- sh ${BUILD_SCRIPT}
- curl -F "file=@${DEPLOY_SCRIPT}" -F "token=654321" -F "uploadSubPath=/${APP_NAME}/${RELEASE}" ${FILE_UP_SERVER}
- curl -F "file=@go-demo.tar.gz" -F "token=654321" -F "uploadSubPath=/${APP_NAME}/${RELEASE}" ${FILE_UP_SERVER}
empty-release:
stage: release
only:
- triggers
tags:
- runInDocker
script:
- echo "empty release."
五,启动pipeline
六,在SonarQube中查看结果
下一步,探索API,看能否直接从bifang中保存每次sonarqube的报告。