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

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
- If you define the same property in both the
sonar-project.propertiesfile and$SD_SONAR_OPTS,$SD_SONAR_OPTSwill override the properties file. - Screwdriver sets the following properties for you:
sonar.host.url,sonar.login,sonar.projectKey,sonar.projectName,sonar.projectVersion,sonar.links.scm,sonar.links.ci; you must setsonar.sourcesyourself. - By default, coverage is not sent for private pipelines. If you want to send coverage, please set
SD_ALLOW_PRIVATE_COVERAGE_SENDtotrue
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
- If you upload code coverage to
$SD_SELF_SONAR_HOST, the code coverage percentage displayed on the UI will beN/A.
Related links
- SonarQube properties
- Java example
- Javascript example
- Examples from the SonarQube website
- SonarQube docs
- SonarQube environment variables
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.