简体   繁体   English

如果 Visual Studio Online 中的代码覆盖率低,则构建失败

[英]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.当代码覆盖率低于阈值时,我试图在 Visual Studio Online 中构建失败。

Is there anyway to do it under Visual Studio Online or I have to do it using the XAML Build Definitions.无论如何都可以在 Visual Studio Online 下完成,或者我必须使用 XAML 构建定义来完成。

It is possible to control build result with code coverage percentage result in both vNext build system and XAML build.可以在 vNext 构建系统和 XAML 构建中使用代码覆盖率百分比结果来控制构建结果。

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.在 vNext 构建中,您需要在构建定义中添加 PowerShell 步骤,并运行一个 PowerShell 脚本来确定构建是失败还是成功。 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查看此博客以了解 PowerShell 脚本的详细信息: 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.如果您使用一个 XAML 构建,则需要创建一个自定义构建活动,其中包含基于代码覆盖率结果失败或通过构建的逻辑。 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请参阅: http : //blogs.msdn.com/b/tfssetup/archive/2015/11/06/controlling-build-result-based-on-code-coverage-percentage-for-xaml-builds.aspx

My preferred method is to use the standard XAML build process in Azure DevOps pipeline.我的首选方法是在 Azure DevOps 管道中使用标准 XAML 构建过程。 Use the code analysis task to fail the build if coverage is below a threshold.如果覆盖率低于阈值,则使用代码分析任务使构建失败。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM