I have code coverage enabled and published in my ADO pull request pipeline. I'm looking at adding code coverage diff to it.
The Microsoft Learn Document doesn't mention how to fail a build if the target diff is not met.
I have 2 asks:
Thanks in Advance.
I have code coverage enabled and published in my ADO pull request pipeline. I'm looking at adding code coverage diff to it.
According to Configuring coverage settings, if you would like to change the default settings of the code coverage experience for pull requests, you must include a configuration YAML file named azurepipelines-coverage.yml at the root of your repo. Set the desired values in this file and it will be used automatically the next time the pipeline runs.
For example,
coverage:
status: # Code coverage status will be posted to pull requests based on targets defined below.
comments: on # Off by default. When on, details about coverage for each file changed will be posted as a pull request comment.
diff: # Diff coverage is code coverage only for the lines changed in a pull request.
target: 60% # Set this to a desired percentage. Default is 70 percent
Result:
How to fail the build if it doesn't meet the target
To fail the build if the code coverage doesn't meet the target, you can install extension Build Quality Checks. For example, fail the build if code coverage is lower than 60%.
- task: BuildQualityChecks@9
inputs:
checkCoverage: true
coverageFailOption: 'fixed'
coverageType: 'lines'
coverageThreshold: '60'
There are many options you can select. See the details about this task from Build Quality Checks.