For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

Onboarding Guide

Walk through integrating code coverage into pipelines

This guide walks you through integrating code coverage into your Harness CI pipeline.

What you will learn from this topic

  • How to connect your repository and configure codebase settings for coverage

  • How to modify your pipeline to generate and upload coverage reports

  • How to set up PR comment integration and quality gates

Before you begin

  • A code repository connected via a Harness connector or a native Harness Code Repository

  • Existing tests in your codebase

  • A valid Harness CI pipeline and license

Step 1: connect your repository

Code coverage requires a repository connection to track changes and calculate patch coverage.

  1. In your Harness pipeline, go to the Build stage

  2. Configure the Codebase section with your Git repository connector

  3. Ensure the connector has:

    • Read access to your repository

    • (Optional) Write access to pull request comments or equivalent

    • (Optional) Write access to status checks or equivalent

Go to Configure codebase for more information on configuring codebases.

Step 2: modify your pipeline to upload coverage

Add coverage commands to the Run step where you execute tests. The approach varies by language:

Step 3: configure PR comment integration (optional)

Harness will automatically post coverage results as comments on your pull requests.

As long as Harness has the ability to write to PRs and status checks, Harness will attempt to post status checks and coverage information on pull requests.

PR comments show:

  • Total coverage percentage

  • Patch coverage percentage

  • Coverage diff compared to the base branch

  • Per-file coverage breakdown

Go to SCM status checks for more information on PR comments.

Step 4: set up CI pipeline quality gates (optional)

Enforce minimum coverage thresholds to prevent merging code that reduces coverage.

Add a quality gate check after uploading coverage:

This command:

  • Waits for coverage data to be processed

  • Checks that total coverage is greater than 70%

  • Checks that patch coverage (for PRs) is greater than 80%

  • Fails the pipeline if thresholds are not met

You can specify one or both thresholds:

Verify your setup

After configuring coverage:

  1. Run your pipeline on a pull request

  2. Go to the Coverage tab in the execution details

  3. Verify coverage metrics appear correctly

  4. Check your pull request for coverage comments (if configured)

  5. Verify you see the coverage UI under Code Quality → Coverage

Troubleshooting

Coverage upload succeeds but the Coverage tab shows no data

Wait a few seconds after the pipeline completes and refresh the page. Coverage data is processed asynchronously. If results still do not appear, confirm the hcli cov upload command ran without errors in the step logs.

Patch coverage does not appear on a pull request

Patch coverage only appears on pull request builds. If your pipeline runs on a branch push (not a PR), only total coverage is shown. Confirm the pipeline was triggered by a pull request event.

Quality gate times out

Increase the --timeout value (for example, --timeout=2m) or check network connectivity between the runner and Harness. If the issue persists, confirm the hcli cov upload step completed before the quality gate step runs.

Next steps

Last updated

Was this helpful?