Code Coverage

After they’re done running, builds can display code coverage percentage in the build UI and upload code coverage data.

Coverage in build detail page

We currently support SonarQube for coverage bookends. Check with your Screwdriver cluster admin to find what coverage plugins are supported to modify your build execution with.

SonarQube

You can configure Sonar properties in your sonar-project.properties file or in your screwdriver.yaml as the $SD_SONAR_OPTS environment variable. The property sonar.sources is always required, and should be set to your source path.

sonar-project.properties

To use SonarQube, add a sonar-project.properties file in the root of your source code and add configurations there.

Example sonar-project.properties file from our Javascript example:

sonar.sources=index.js
sonar.javascript.lcov.reportPaths=artifacts/coverage/lcov.info

The reportPath property depends on the language used. Check the SonarQube documentation to figure out the right syntax.

$SD_SONAR_OPTS

Alternatively, you can add configurations to the environment variable $SD_SONAR_OPTS.

Example screwdriver.yaml:

shared:
  environment:
    SD_SONAR_OPTS: '-Dsonar.sources=lib -Dsonar.javascript.lcov.reportPaths=artifacts/coverage/lcov.info'
jobs:
  main:
    requires: [~pr, ~commit]
    image: node:lts
    steps:
      - install: npm install
      - test: npm test

Notes

Use a self-hosted SonarQube

You can upload code coverage to a host that is not configured for the Screwdriver cluster by setting the Sonar host URL in the environment variable $SD_SELF_SONAR_HOST.
If you use $SD_SELF_SONAR_HOST, you must set the admin’s User Token for that host in the environment variable $SD_SELF_SONAR_ADMIN_TOKEN.

Example screwdriver.yaml:

jobs:
  main:
    requires: [~pr, ~commit]
    image: node:lts
    steps:
      - install: npm install
      - test: npm test
  environment:
    SD_SELF_SONAR_HOST: 'http://YOUR_SONAR_URL'
  secrets:
    - SD_SELF_SONAR_ADMIN_TOKEN

Notes

GitHub pull request decoration

If your Screwdriver cluster supports Sonar Enterprise, you might have the ability to add Pull Request decoration to Checks in GitHub. If this feature is supported, you can enable it by adding the Screwdriver Sonar PR Checks GitHub app to your repository. Check with your Screwdriver cluster admin for support details.