【问题标题】:Teamcity not failing build after test report xml importTeamcity 在测试报告 xml 导入后没有失败构建
【发布时间】:2012-11-04 12:17:16
【问题描述】:

我有一个小型 powershell 任务,它使用 Gallio 运行我的所有单元测试,并且 teamcity 会导入报告,但不会使构建步骤失败,也不会显示失败或通过的测试数量。

那么,如何让 teamcity 根据报告中的测试使构建失败,以及如何让它显示通过、忽略和失败的测试数量。

Add-PSSnapIn Gallio
$fileList = Get-ChildItem ./source/ -filter *.Unittests.dll -Recurse | where { $_.FullName -like "*\bin\*" } | %{$_.FullName}
Run-Gallio -Files $fileList -ReportTypes XML -ReportNameFormat unittests
Write-Output "##teamcity[importData type='nunit' path='./Reports/unittests.xml']"

日志显示文件通过

[Step 2/2] NUnit report watcher
[12:39:11][NUnit report watcher] 1 report found for paths:
[12:39:11][NUnit report watcher] C:\TeamCity\buildAgent\work\416967dfd65045\Reports\unittests.xml
[12:39:11][NUnit report watcher] Successfully parsed

我正在使用 teamcity 7.1.1

【问题讨论】:

    标签: powershell gallio teamcity-7.0


    【解决方案1】:

    您需要确保 Powershell 以非零退出代码(例如 1)退出,以便 TeamCity 注意到非零代码并因错误而停止构建。

    为此,请在脚本中添加如下内容:

      $host.SetShouldExit(1);
      exit 1;
    

    这将导致 Powershell 以错误代码 1 退出。

    您可以编写脚本以捕获异常(例如测试失败),然后如上所示退出。这可以使用陷阱语句(powershell 1)或 try/catch(powershell 2 及更高版本)来完成。

    【讨论】:

    • 这并没有真正回答问题(没有尝试过) - 因为如果没有错误,它仍然没有报告解析的测试数量。我已经放弃从 powershell 运行构建,只是从 msbuild 运行测试。
    猜你喜欢
    • 2018-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    相关资源
    最近更新 更多