TeamCity命令行构建转轮:如何使构建失败? [英] TeamCity command line build runner: How to make the build fail?

查看:259
本文介绍了TeamCity命令行构建转轮:如何使构建失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用TeamCity的命令行构建运行器来调用bat文件。 bat文件通过调用Visual Studio 2008的devenv.exe构建我们的解决方案,然后执行单元测试并创建正确的文件夹结构。

We're using TeamCity's command line build runner to call a bat-file. The bat-file builds our solution by calling the Visual Studio 2008's "devenv.exe" and then it executes the unit tests and creates the correct folder structure.

我们想做的是停止执行bat文件,如果调用devenv失败,并使TeamCity意识到构建失败。我们可以通过检查 ErrorLevel (如果构建失败,则为1)捕获失败的devenv调用,我们可以在那时退出bat文件。

What we would like to do is to stop executing the bat-file if the call to devenv fails and make the TeamCity to realize that the build failed. We can catch the failed devenv call by checking the ErrorLevel (which is 1 if the build failed) and we can exit our bat-file at that point. But how can we tell to the TeamCity that the build failed?

这是我们尝试过的:

call "build.bat"
IF ERRORLEVEL 1 EXIT /B 1

但TeamCity无法识别我们的退出代码。相反,构建日志如下所示:

But TeamCity doesn't recognize our exit code. Instead the build log looks like this:

[08:52:12]: ========== Build: 28 succeeded or up-to-date, 1 failed, 0 skipped ==========
[08:52:13]: C:\_work\BuildAgent\work\bcd14331c8d63b39\Build>IF ERRORLEVEL 1 EXIT /B 1 
[08:52:13]: Process exited with code 0
[08:52:13]: Publishing artifacts
[08:52:13]: [Publishing artifacts] Paths to publish: [build/install, teamcity-info.xml]
[08:52:13]: [Publishing artifacts] Artifacts path build/install not found
[08:52:13]: [Publishing artifacts] Publishing files
[08:52:13]: Build finished

所以TeamCity会报告构建成功。我们如何解决此问题?

So TeamCity will report that the build was successful. How can we fix this?

解决方案:

TeamCity提供了一种机制服务消息,可以使用以处理这种情况。
我已经更新了我的构建脚本,如下所示:

TeamCity provides a mechanism called Service Messages which can be used to handle situations like this. I've updated my build script to look like the following:

IF %ERRORLEVEL% == 0 GOTO OK
echo ##teamcity[buildStatus status='FAILURE' text='{build.status.text} in compilation']
EXIT /B 1
:OK

因此TeamCity会报告我的构建失败,因为编译失败。

As a result TeamCity will report my build as failed because of a "Failure in compilation".

推荐答案

请参阅

See Build Script Interaction with TeamCity topic.


您可以在以下内容中报告构建日志的消息:rel =nofollow noreferrer> Build Script Interaction with TeamCity topic。方式:

You can report messages for build log in the following way:

## teamcity [message text ='< message text>'errorDetails ='< error details>'status ='< ;状态值>']

其中:


  • status属性可以取以下值:NORMAL,WARNING,
    FAILURE,ERROR。默认值为NORMAL。

  • errorDetails
    属性仅在状态为ERROR时使用,在其他情况下为

此消息在构建状态为ERROR且
时失败构建如果构建运行程序记录错误消息,则失败构建复选框是
在构建配置常规设置页面上选中。例如:

This message fails the build in case its status is ERROR and "Fail build if an error message is logged by build runner" checkbox is checked on build configuration general settings page. For example:

## teamcity [message text ='异常文本'errorDetails ='stack trace'status ='ERROR']

更新2013-08-30:

从TeamCity 7.1构建失败应该报告使用 buildProblem 服务讯息:

As of TeamCity 7.1 build failures should be reported using the buildProblem service message instead:

##teamcity[buildProblem description='<description>' identity='<identity>']

这篇关于TeamCity命令行构建转轮:如何使构建失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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