TFS 2017-发布的测试失败时如何失败构建

TFS 2017-发布的测试失败时如何失败构建

问题描述:

我在TFS 2017中使用CI / CD演示有一个简单的构建过程,如 https://msdn.microsoft.com/zh-cn/powershell/dsc/dsccicd

I have a simple build process in TFS 2017 using CI/CD demo as described in https://msdn.microsoft.com/en-us/powershell/dsc/dsccicd

内部版本定义包含四个步骤:

The Build definition contains four steps:


  • 运行powershell脚本。作为脚本的一部分,Pester测试将在代理上运行,并使用NUnit格式将结果保存到文件夹中。

  • 使用该文件夹中的测试结果发布

  • 将文件复制到暂存目录

  • 发布工件

  • Run powershell script. As a part of the script, Pester tests are run on agent and results are saved to a folder using NUnit format
  • Publish Test results using from that folder
  • Copy files to staging directory
  • Publish Artifacts

当Pester测试失败时,我会就像整个构建失败一样。目前,即使发布的测试结果显示为失败,构建也成功(构建详细信息的发行部分)。
我看不到如何强制整个构建失败以查看构建定义参数。

When Pester test fails , I would like entire build to fail. At the moment build succeeds even when Published Test results show as failed ( In Issues section of Build Details). I don't see how can I force entire build to fail looking at the Build definition parameters.

I不是使用TFS,而是在我的构建过程中,测试失败通过输出错误触发构建失败。

I'm not using TFS, but in my build process test failures trigger the build to fail by outputting an error.

这是通过将 -PassThru 开关添加到 Invoke-Peter 并将命令结果发送到变量:

This is done by adding the -PassThru switch to Invoke-Peter and sending the results of the command to a variable:

$TestResults = Invoke-Pester -Path .\Tests -PassThru

然后在测试失败的情况下写一个错误:

Then writing an error if there are any failed tests:

if($TestResults.FailedCount -gt 0)
{
    Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed"
}

然后在脚本中使用调用PSake

exit ( [int]( -not $psake.build_success ) )