2

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:

  1. How to fail the build if it doesn't meet the target
  2. How to avoid the build from failing. I want to wait for the team to get mature on this and slowly enable the gate check. Until then, I don't want it to fail the build.

Thanks in Advance.

1
  • It is contradictory, you want the build to fail when the code coverage does not meet the target, and you also want to avoid the build from failing. Commented Apr 4 at 8:11

2 Answers 2

1

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

enter image description here

Result:

enter image description here

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'

enter image description here

There are many options you can select. See the details about this task from Build Quality Checks.

Sign up to request clarification or add additional context in comments.

Comments

1

With the NDepend AzureDevOps extension you can use and customize the Quality Gates related to code coverage to eventually fail the build.

You can define different coverage thresholds for:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.