TeamCity的建设运行,即使测试失败的步骤 [英] Teamcity running build steps even when tests fail

查看:596
本文介绍了TeamCity的建设运行,即使测试失败的步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在那里继续运行生成步骤,即使previous那些成功的TeamCity ,存在的问题。

我的构建配置的最后一步部署我的网站,我不希望它,如果我的任何测试失败做的。

The final step of my Build configuration deploys my site, which I do not want it to do if any of my tests fail.

每个构建步骤设置为只执行,如果所有previous措施是成功的。

Each build step is set to only execute if all previous steps were successful.

在构建失败条件选项卡,我已经检查失败下的以下选项,如果建:

In the Build Failure Conditions tab, I have checked the following options under Fail build if:

-build process exit code is not zero
-at least one test failed
-an out-of-memory or crash is detected (Java only)

这不工作 - 甚至当测试失败的TeamCity部署我的网站,为什么

This doesn't work - even when tests fail TeamCity deploys my site, why?

我甚至试图添加将查找在构建日志特定文本的额外构建失败条件(即测试运行失败。)

I even tried to add an additional build failure condition that will look for specific text in the build log (namely "Test Run Failed.")

当观看在概述页面已完成测试,可以看到对最新版本的错误消息:

When viewing a completed test in the overview page, you can see the error message against the latest build:

测试运行失败。文字出现在构建日志

"Test Run Failed." text appeared in build log

但它仍然部署也无妨。

有谁知道如何解决这一问题?看来,这个问题已经运行了很长一段时间,这里

Does anyone know how to fix this? It appears that the issue has been running for a long time, here.

显然有解决方法:

到目前为止,我们不会因为有考虑这个功能非常重要
  一个明显的解决方法:脚本可以检查的必要条件
  并在TeamCity的配置不产生伪影。

So far we do not consider this feature as very important as there is an obvious workaround: the script can check the necessary condition and do not produce the artifacts as configured in TeamCity.

例如。一个脚本可以从临时目录到移动文物
  在TeamCity的指定目录从刚刚公布的文物
  结束前,以防生成操作是成功的。

e.g. a script can move the artifacts from a temporary directory to the directory specified in the TeamCity as publish artifacts from just before the finish and in case the build operations were successful.

但是,这并不清楚,我就究竟是如何做到这一点,听起来不像最好的解决方案无论是。任何帮助AP preciated。

But that is not clear to me on exactly how to do that, and doesn't sound like the best solution either. Any help appreciated.

修改:我也能够通过快照依赖,在那里我将有一个单独的部署建设,这是依赖于测试版本要解决的问题,现在它不运行如果测试失败。

Edit: I was also able to workaround the problem with a snapshot dependency, where I would have a separate 'deploy' build that was dependent on the test build, and now it doesn't run if tests fail.

是设置的依赖非常有用。

This was useful for setting the dependency up.

推荐答案

这是一个已知的问题,因为TeamCity的7.1(比照的 http://youtrack.jetbrains.com/issue/TW-17002 ),它已被固定在TeamCity的8.x的+(见的这个答案)。

This is a known problem as of TeamCity 7.1 (cf. http://youtrack.jetbrains.com/issue/TW-17002) which has been fixed in TeamCity 8.x+ (see this answer).

TeamCity的区分一个失败的建立的和失败的生成步骤的。虽然失败的单元测试将失败的构建作为一个整体,遗憾的TeamCity仍然认为测试步骤本身成功的,因为它没有返回一个非零的错误code 的。其结果是,随后的步骤将继续运行。

TeamCity distinguishes between a failed build and a failed build step. While a failing unit test will fail the build as a whole, unfortunately TeamCity still considers the test step itself successful because it did not return a non-zero error code. As a result, subsequent steps will continue running.

一个解决方法各种已经提出,但我发现他们要么需要在TeamCity的测试经历不平凡的设置或妥协。

A variety of workarounds have been proposed, but I've found they either require non-trivial setup or compromise on the testing experience in TeamCity.

不过,审查后,<一个href=\"http://stackoverflow.com/questions/13212748/how-to-integrate-mstest-in-your-teamcity-build-process/\">suggestion从@ arex1337 ,我们发现了一个简单的方法得到的TeamCity做我们想要的。只是,包含以下内嵌脚本现有的测试步骤后添加一个额外的PowerShell的构建步骤(更换 YO​​UR_TEAMCITY_HOSTNAME 与您的实际TeamCity的主机/域):

However, after reviewing a suggestion from @arex1337, we found an easy way to get TeamCity to do what we want. Just add an extra Powershell build step after your existing test step that contains the following inline script (replacing YOUR_TEAMCITY_HOSTNAME with your actual TeamCity host/domain):

$request = [System.Net.WebRequest]::Create("http://YOUR_TEAMCITY_HOSTNAME/guestAuth/app/rest/builds/%teamcity.build.id%")
$xml = [xml](new-object System.IO.StreamReader $request.GetResponse().GetResponseStream()).ReadToEnd()
Microsoft.PowerShell.Utility\Select-Xml $xml -XPath "/build" | % { $status = $_.Node.status }

if ($status -eq "FAILURE") {
    throw "Failing this step because the build itself is considered failed. This is our way to workaround the fact that TeamCity incorrectly considers a test step to be successful even if there are test failures. See http://youtrack.jetbrains.com/issue/TW-17002"
}

本直列PowerShell脚本只是使用TeamCity的REST API问构建本身与否,作为一个整体,将视为失败(变量%teamcity.build.id%将由TeamCity的被替换。如果构建作为一个整体被认为是失败的(比如说,由于测试失败),那么这个PowerShell脚本抛出一个错误,导致在执行步的实际版本ID)过程返回一个非零的错误code的这会导致个人的构建步骤本身被认为是不成功的的。在这一点上,后续步骤可以从运行pvented $ p $

This inline PowerShell script is just using the TeamCity REST API to ask whether or not the build itself, as a whole, is considered failed (the variable %teamcity.build.id%" will be replaced by TeamCity with the actual build id when the step is executed). If the build as a whole is considered failed (say, due to a test failure), then this PowerShell script throws an error, causing the process to return a non-zero error code which results in the individual build step itself to be considered unsuccessful. At that point, subsequent steps can be prevented from running.

请注意,此脚本使用guestAuth,这就要求要启用的TeamCity的来宾帐户。或者,你可以使用httpAuth代替,但你需要更新脚本包括一个TeamCity的用户名和密码(例如<$c$c>http://USERNAME:PASSWORD@YOUR_TEAMCITY_HOSTNAME/httpAuth/app/rest/builds/%teamcity.build.id%).

Note that this script uses guestAuth, which requires the TeamCity guest account to be enabled. Alternately, you can use httpAuth instead, but you'll need to update the script to include a TeamCity username and password (e.g. http://USERNAME:PASSWORD@YOUR_TEAMCITY_HOSTNAME/httpAuth/app/rest/builds/%teamcity.build.id%).

所以,有了这个额外的步骤,所有的后续步骤设置实行只有当所有的previous措施是成功的,如果有任何previous单元测试失败将被跳过。如果我们的任何NUnit的测试都没有成功,我们正在使用这prevent自动部署到JetBrains公司解决了这个问题。

So, with this additional step in place, all subsequent steps set to execute "Only if all previous steps were successful" will be skipped if there are any previous unit test failures. We're using this to prevent automated deployment if any of our NUnit tests are not successful until JetBrains fixes the problem.

<一个href=\"http://stackoverflow.com/questions/13212748/how-to-integrate-mstest-in-your-teamcity-build-process/\">Thanks在@ arex1337为理念。

这篇关于TeamCity的建设运行,即使测试失败的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆