Gitlab CI 找不到 sonarqube 覆盖率报告,在本地工作

Gitlab CI cannot find sonarqube coverage report, does work locally

我有一个 angular 通过 gitlab ci 部署的应用程序。尽管 none 的代码覆盖率报告不幸出现

,但部署到托管 Sonarqube 实例确实通过了

我的gitlab yml文件如下


stages:
  - test
  - deploy

unittests:
  image: markhobson/node-chrome:latest
  stage: test
  variables:
    NODE_ENV: development
  before_script:
    - npm install
  script: 
    - npm run test
    - npm run sonar


production:
  type: deploy
  stage: deploy
  image: ruby:latest
  script:
    - echo "Heroku api key = $HEROKU_API_KEY"
    - echo "Heroku appname = $HEROKU_APP_NAME"
    - apt-get update -qy
    - apt-get install -y ruby-dev
    - gem install dpl
    - dpl --provider=heroku --app=$HEROKU_APP_NAME --api-key=$HEROKU_API_KEY
  only:
    - master

而我的sonar-project.properties文件如下

sonar.host.url=HOSTURL

sonar.projectKey=SONARKEYNAME
sonar.login=
sonar.password=
sonar.projectName=SONARKEYNAME
sonar.gitlab.project_id=GITLABURL

sonar.typescript.lcov.reportPaths=/coverage/client/lcov.info
sonar.javascript.lcov.reportPaths=/coverage/client/lcov.info

# --- optional properties ---
sonar.projectVersion=0.0.1
sonar.exclusions=client/node_modules/**, node_modules/**
sonar.sourceEncoding=UTF-8
sonar.verbose=false
sonar.working.directory=.scannerwork

sonar.projectBaseDir=.
sonar.sources=./src/app
sonar.sourceEncoding=UTF-8

sonar.exclusions=node_modules/**,**/*.spec.ts,**/*.css
sonar.test.inclusions=**/*.spec.ts

每当我通过 CI 部署应用程序时,我都会收到以下消息:

Provided LCOV file path: coverage/client/lcov.info. Seek file with the path: /builds/USERNAME/REPONAME/coverage/client/lcov.info
No coverage information will be saved because all LCOV report files cannot be found.

有谁知道如何解决这个错误以及为什么在 运行 本地声纳扫描(没有 CI)

时不会发生

经过长时间的搜索后发现,angular.json 设置中没有启用代码覆盖率。我在 "test" 下添加了以下内容:

          "options": {
            "codeCoverage": true,
            "main": "src/test.ts"
           }

gitlab CI 和 运行 本地命令

的覆盖率正确显示