Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 for coverage tracking

  • How to modify your pipeline to upload coverage reports for Python, Java, Go, and Node.js

  • How to configure 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 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)

When Harness has write access to PRs and status checks, it posts coverage results as comments on your 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 command not found

Ensure hcli is installed in your pipeline environment. Go to Onboarding Guide for setup steps.

Quality gate fails unexpectedly

Check that coverage was uploaded before calling hcli cov wait-until. Verify the threshold values match your project goals. Go to Advanced Settings for threshold options.

Next steps

Last updated

Was this helpful?