我在 Azure DevOps 中有一个用于 ASP.NET Core 应用程序的构建管道,我想将其与批准拉取请求的条件一起使用。
steps:
- script: dotnet restore
displayName: 'Run command: dotnet restore'
- script: >
dotnet test
/p:CollectCoverage=true
/p:CoverletOutputFormat=cobertura
/p:Threshold=80
/p:ThresholdStat=total
/p:Exclude="[*xunit.*]*"
displayName: 'Run command: dotnet test'
我希望当代码覆盖率(使用 coverlet)未通过时,构建失败。但是尽管验收标准没有通过,即使生成了一条日志消息,该步骤也成功运行。
coverlet.msbuild.targets(41,5): error : The total line coverage is below the specified 80 coverlet.msbuild.targets(41,5): error : The total branch coverage is below the specified 80 coverlet.msbuild.targets(41,5): error : The total method coverage is below the specified 80
在这种情况下有可能强制失败吗?
最佳答案
尝试使用DotNetCoreCLI@2
任务而不是简单的脚本
运行测试:
- task: DotNetCoreCLI@2
displayName: 'dotnet test'
inputs:
commands: test
projects: 'path/to/tests/projects'
arguments: 'p:CollectCoverage=true
/p:CoverletOutputFormat=cobertura /p:Threshold=80
/p:ThresholdStat=total /p:Exclude="[*xunit.*]"'
关于asp.net-core - 当 dotnet 测试的覆盖率低于目标时,Azure DevOps 构建不会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56631066/