Skip to main content

Code coverage with CodeCov in Harness CI

This tutorial shows how you can use a Run step to include CodeCov code coverage in a Harness CI pipeline.


In addition to a Harness account, this tutorial requires the following:


If you don't have a Harness account yet, you can create one for free at

Add CodeCov Upload Token secret

Follow the steps in Add and reference text secrets to store your CodeCov Upload Token as a secret in Harness.

Add the Run step

To include CodeCov code coverage in a Harness CI pipeline, add a Run step that does the following:

  1. In Harness, go to the Build stage in the pipeline where you want to include CodeCov.

  2. Select Add Step, select Add Step again, and then select Run in the Step Library.

  3. Enter a Name for the step.

  4. Depending on the stage's build infrastructure, specify the Container Registry and Image containing the binaries that the step needs to run your script. For example, the command example below uses pytest and might require a pytest image, such as pytest:latest. For information about when these fields are required and how to specify images, go to Use Run steps.

  5. In the Command field, include all commands necessary to prepare the test environment, run tests with code coverage, and download and run the CodeCov Uploader tool. For example:

    echo "Welcome to Harness CI"
    uname -a
    pip install pytest
    pip install pytest-cov
    pip install -r requirements.txt

    pytest -v --cov --junitxml="result.xml"

    # Download Codecov uploader and run it.
    curl -Os
    chmod +x codecov
    ./codecov -t ${CODECOV_TOKEN}
  6. Under Optional Configuration, add a CODECOV_TOKEN Environment Variable:

  7. Under Optional Configuration, add one or more Report Paths, such as **/*.xml.

  8. Select Apply Changes to save the step, and then select Save to save the pipeline.

For more information about Run step settings, go to Use Run steps.

Run the pipeline

After adding the Run step, run your pipeline.

On the Build details page, you can review CodeCov information in the Run step's logs. If the results were successfully uploaded to CodeCov, the logs include a resultURL that you can follow to view the code coverage output in your CodeCov account, such as:

145 info [date] [time] [timestamp] [`info`] Uploading...
146 info [date] [time] [timestamp] [`info`] {"status":"success","resultURL":""}