Publish Code Coverage Results task

Azure Pipelines | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 - TFS 2015

Use this task in a build pipeline to publish code coverage results produced when running tests to Azure Pipelines or TFS in order to obtain coverage reporting. The task supports popular coverage result formats such as Cobertura and JaCoCo.

This task can only be used in Build pipelines and is not supported in Release pipelines.

Tasks such as Visual Studio Test, .NET Core, Ant, Maven, Gulp, Grunt also provide the option to publish code coverage data to the pipeline. If you are using these tasks, you do not need a separate Publish Code Coverage Results task in the pipeline.

Demands

To generate the HTML code coverage report you need dotnet 2.0.0 or later on the agent. The dotnet folder needs to be in the environment path. If there are multiple folders containing dotnet, the one with version 2.0.0 must be before any others in the path list.

YAML snippet

# Publish code coverage results
# Publish Cobertura or JaCoCo code coverage results from a build
- task: PublishCodeCoverageResults@1
  inputs:
    #codeCoverageTool: 'JaCoCo' # Options: cobertura, jaCoCo
    summaryFileLocation: 
    #pathToSources: # Optional
    #reportDirectory: # Optional
    #additionalCodeCoverageFiles: # Optional
    #failIfCoverageEmpty: false # Optional

The codeCoverageTool and summaryFileLocation parameters are mandatory.

To publish code coverage results for Javascript with istanbul using YAML, see JavaScript in the Ecosystems section of these topics, which also includes examples for other languages.

Arguments

Argument Description
summaryFileLocation
Path to summary files
(Required) Path of the summary file containing code coverage statistics, such as line, method, and class coverage. The value may contain minimatch patterns.
For example: $(System.DefaultWorkingDirectory)/MyApp/**/site/cobertura/coverage.xml
pathToSources
Path to Source files
(Optional) Path to source files is required when coverage XML reports do not contain absolute path to source files.
For example, JaCoCo reports do not use absolute paths and when publishing JaCoCo coverage for Java apps, the pattern would be similar to $(System.DefaultWorkingDirectory)/MyApp/src/main/java/.
This input is also needed if tests are run in a docker container. This input should point to absolute path to source files on the host.
For example, $(System.DefaultWorkingDirectory)/MyApp/
failIfCoverageEmpty
Fail if code coverage results are missing
(Optional) Fail the task if code coverage did not produce any results to publish.

Docker

For apps using docker, build and tests may run inside the container, generating code coverage results within the container. In order to publish the results to the pipeline, the resulting artifacts should be to be made available to the Publish Code Coverage Results task. For reference you can see a similar example for publishing test results under Build, test, and publish results with a Docker file section for Docker.

View results

In order to view the code coverage results in the pipeline, see Review code coverage results

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

FAQ

Is code coverage data merged when multiple files are provided as input to the task or multiple tasks are used in the pipeline?

At present, the code coverage reporting functionality provided by this task is limited and it does not merge coverage data. If you provide multiple files as input to the task, only the first match is considered. If you use multiple publish code coverage tasks in the pipeline, the summary and report is shown for the last task. Any previously uploaded data is ignored.

Help and support