stages:
  - analysis
  - sendmail

## 代码检查
sonarqube_analysis:
  tags:
    - offline-test
  stage: analysis
  image: sonarsource/sonar-scanner-cli:latest
  dependencies: []    #禁止传递来的artifact
  script:
    ## 获取项目的一级组和二级组和项目名作为projectKey，例如projectKey=platform-backend-eci-monitor
    - group=`echo $CI_PROJECT_PATH | sed 's#/#-#g'`
    - sonar-scanner
      -Dsonar.host.url=http://sonarqube-server.sonarqube:9000/
      -Dsonar.login=be43de7264ce4c4766eb0c020373c3e74e6df257
      -Dsonar.jacoco.reportPaths=target/jacoco.exec
      -Dsonar.projectKey=$group
      -Dsonar.projectName=$CI_PROJECT_PATH
      -Dsonar.sourceEncoding=UTF-8
      -Dsonar.exclusions=**/vendor/**,**/errcode/**
      -Dsonar.gitlab.project_id=$CI_PROJECT_ID
      -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA
      -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
      -Dsonar.gitlab.ci_merge_request_iid=$CI_MERGE_REQUEST_IID
      -Dsonar.gitlab.merge_request_discussion=true
      -Dsonar.java.binaries=.                 # 如果不使用Maven或Gradle进行分析，则必须手动提供测试二进制文件
  only:
    - dev
 
## 发送简易检测结果报告
send_sonar_report:
  tags:
    - offline-test
  stage: sendmail
  image: hub.shanqu.cc/library/docker:latest
  dependencies: []    #禁止传递来的artifact
  script:
    - group=`echo $CI_PROJECT_PATH | sed 's#/#-#g'`
    - docker run -e PROJECTKEY=$group -e EMAIL=$GITLAB_USER_EMAIL --name send-email --rm hub.shanqu.cc/platform/send-sonar-report:latest
  only:
    - dev
