从 powershell 执行时,Teamcity 不会检测到 msbuild 或 nUnit 故障

发布于 2024-12-11 15:05:07 字数 479 浏览 0 评论 0原文

我已经使用 psake 编写了一个构建脚本,我在 Teamcity 中运行该脚本。

我有 Teamcity 6.0,所以我从 .cmd 运行 psake,但我认为这不会改变任何东西。

一切工作正常,但我有两个问题。

  1. Nunit 不与 Teamcity 通信,因此当测试失败时,Teamcity 会表示一切正常。

  2. MsBuild 的行为相同。即使构建失败,Teamcity 也会报告成功。

我想知道如何让 Teamcity 检测这些故障。

这是我的示例脚本: https://github.com/MikeEast/BuildTests /blob/master/build/build.ps1

I have written a build script using psake which I run in Teamcity.

I have Teamcity 6.0, so I run psake from a .cmd, but I don't think that changes anything.

Everything is working fine, but I have two problems.

  1. Nunit isn't communicating with Teamcity so when a test fails, Teamcity says everything is ok.

  2. MsBuild behaves the same. Even though the build fails, Teamcity reports success.

I would like to know how get Teamcity to detect these failures.

Here is my example script: https://github.com/MikeEast/BuildTests/blob/master/build/build.ps1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里泪两行 2024-12-18 15:05:07

您可能需要通过其简单而优雅的 建立状态通知系统

例如,您可以在 powershell 脚本期间将以下消息输出到 stdout。

##teamcity[buildStatus status='FAILURE' text='Some error message']

You will probably need to notify Teamcity yourself via its simple but elegant build status notification system.

For example, you could output the following message to stdout during your powershell script.

##teamcity[buildStatus status='FAILURE' text='Some error message']
夜司空 2024-12-18 15:05:07

我让 TeamCity 工作的方法(我必须添加 TeamCity 版本 6.5.4)是使用 psake 下载中提供的 TeamCity 模块。

将其添加到您的脚本中:

...
Import-Module "$build_dir\psake\teamcity.psm1"

#Tasks here
...
Remove-Module teamcity

#End Of File

我有一个构建文件夹,我已将模块放入其中,以便我的所有构建都可以访问它。

然后它开箱即用。

不过,我没有使用内置的 NUnit 运行程序,我还将 NUUnit 控制台放入我的构建文件夹中,然后使用每个 UnitTest 程序集调用它:

Task Test -depends Build {
    $testAssemblies = (get-childitem $base_dir -r -i "*UnitTests.dll" -exclude "*.config" -Name | Select-string "bin")
    foreach($test_asm_name in $testAssemblies) {
        $full_test_assembly_name = "$base_dir\$test_asm_name"
        Exec { invoke-expression "$nunitconsole_path $full_test_assembly_name" }
    }
}

The way I have got TeamCity working (with TeamCity version 6.5.4 I must add) is to use the TeamCity module that is provided in the psake download.

Add this to your script:

...
Import-Module "$build_dir\psake\teamcity.psm1"

#Tasks here
...
Remove-Module teamcity

#End Of File

I have a build folder that I have put the module in so that all my builds can access it.

Then it worked out of the box.

I am not using the built in NUnit runner though, I have also put the NUNit console in my build folder and then call that with each UnitTest assembly:

Task Test -depends Build {
    $testAssemblies = (get-childitem $base_dir -r -i "*UnitTests.dll" -exclude "*.config" -Name | Select-string "bin")
    foreach($test_asm_name in $testAssemblies) {
        $full_test_assembly_name = "$base_dir\$test_asm_name"
        Exec { invoke-expression "$nunitconsole_path $full_test_assembly_name" }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文