CI/CD

简单示范使用SonarQube在gitlab ci/cd中扫描g

2021-01-25  本文已影响0人  万州客

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/**

四,重新定义.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


2021-01-24 13_25_19-悬浮球.png

六,在SonarQube中查看结果


2021-01-24 13_25_54-悬浮球.png

下一步,探索API,看能否直接从bifang中保存每次sonarqube的报告。

上一篇 下一篇

猜你喜欢

热点阅读