PublishCodeCoverageResults@2 - Publish code coverage results v2 task
Use this task to get code coverage results from a build.
Syntax
# Publish code coverage results v2
# Publish any of the code coverage results from a build.
- task: PublishCodeCoverageResults@2
inputs:
summaryFileLocation: # string. Required. Path to summary files.
#pathToSources: # string. Path to Source files.
#failIfCoverageEmpty: false # boolean. Fail if code coverage results are missing. Default: false.
Inputs
summaryFileLocation
- Path to summary files
string
. Required.
Specifies the path of the summary file containing code coverage statistics, such as line, method, and class coverage. Multiple summary files are merged into a single report. The value may contain minimatch patterns. For example: $(System.DefaultWorkingDirectory)/MyApp/**/site/cobertura/coverage.xml
. More information on minimatch patterns.
pathToSources
- Path to Source files
string
.
Specifying a path to source files is required when coverage XML reports don't contain an absolute path to source files. For example, JaCoCo reports don't use absolute paths, so when publishing JaCoCo coverage for Java apps, the pattern is similar to $(System.DefaultWorkingDirectory)/MyApp/src/main/java/
. This input should point to an absolute path to source files on the host. For example, $(System.DefaultWorkingDirectory)/MyApp/
.
This input can be used if tests are run in a Docker container.
failIfCoverageEmpty
- Fail if code coverage results are missing
boolean
. Default value: false
.
Fails the task if code coverage did not produce any results to publish.
Task control options
All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.
Output variables
None.
Remarks
Note
See New version of Publish Code Coverage Results task on the Azure DevOps blog for information about the new features in V2 of the Publish Code Coverage Results task, and migrating from V1 to V2.
Use this task in a build pipeline to publish code coverage results produced when running tests to Azure Pipelines or TFS and after generating the coverage xml files in order to obtain code coverage tab and coverage reporting details in the pipeline. The task supports code coverage generated xml formats. This task generates a cjson file which contains the code coverage details. It will also produce a code coverage HTML report under the build artifacts.
This task is only supported in build pipelines, not release pipelines.
Tasks such as Visual Studio Test, .NET Core, Ant, Maven, Gulp, and 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.
Prerequisite- To use the Publish Code Coverage Results v2 task in the pipeline, please use the dotnet 7.0.x task as a pre-requisite in the pipeline. Use the dotnet core task before the Publish Code Coverage v2 task.
Prerequisites
To configure the prerequisites using a YAML pipeline:
# Dotnet core sdk task 7.0.x
- task: UseDotNet@2
displayName: 'Use .NET Core sdk 7.0.x'
inputs:
version: 7.0.x
To configure the prerequisites using the designer:
Configure the Publish Code Coverage Results version 2 task using the following settings.
After the build completes and the Publish Code Coverage Results v2 task succeeds, select the Code Coverage tab in the pipeline run summary to view the code coverage results.
Code coverage results for JavaScript with Istanbul using YAML
To publish code coverage results for JavaScript with Istanbul using YAML, see Customize JavaScript in the Ecosystems section of these topics, which also includes examples for other languages.
See an example of publishing code coverage using Cobertura.
Docker
For apps using Docker, build and tests may run inside the container and generate code coverage results within the container. In order to publish the results to the pipeline, the resulting artifacts should be made available to the Publish Code Coverage Results task. For reference, you can see a similar example for publishing test results under the 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.
Known issues
The publish code coverage results v2 task generates a cjson file and publishes the code coverage report under the code coverage tab. It also produces a build artifacts which is a set of HTML files that are linked from the main index.html file. If the code coverage tab fails to show the code coverage report, check whether the input code coverage xml file is in the correct format and has the valid details.
Requirements
Requirement | Description |
---|---|
Pipeline types | YAML, Classic build |
Runs on | Agent |
Demands | None |
Capabilities | This task does not satisfy any demands for subsequent tasks in the job. |
Command restrictions | Any |
Settable variables | Any |
Agent version | 2.144.0 or greater |
Task category | Test |