ELE
ELE

Reputation: 23

Fail a Build if Code Coverage is Low in Visual Studio Online

I'm trying to fail builds in Visual Studio Online when Code Coverage is below a threshold.

Is there anyway to do it under Visual Studio Online or I have to do it using the XAML Build Definitions.

Upvotes: 2

Views: 2703

Answers (2)

David Rupe
David Rupe

Reputation: 113

My preferred method is to use the standard XAML build process in Azure DevOps pipeline. Use the code analysis task to fail the build if coverage is below a threshold.

See: https://learn.microsoft.com/en-us/archive/blogs/tfssetup/controlling-build-result-based-on-code-coverage-percentage-for-xaml-builds

Upvotes: 0

Vicky - MSFT
Vicky - MSFT

Reputation: 5010

It is possible to control build result with code coverage percentage result in both vNext build system and XAML build.

In vNext build, you need to add the PowerShell step in the build definition, and run one PowerShell script to determine whether the build failed or succeed. Check this blog for the details of the PowerShell script: http://blogs.msdn.com/b/tfssetup/archive/2015/11/06/controlling-build-result-with-code-coverage-percentage-using-build-vnext.aspx

If you work with one XAML build, you need to create a custom build activity in which contains the logic to fail or pass a build based on code coverage result. Then include to use the build activity in the build definition. See: http://blogs.msdn.com/b/tfssetup/archive/2015/11/06/controlling-build-result-based-on-code-coverage-percentage-for-xaml-builds.aspx

Upvotes: 4

Related Questions