【问题标题】:TeamCity command line build runner: How to make the build fail?TeamCity 命令行构建运行器:如何使构建失败?
【发布时间】:2011-04-10 02:30:39
【问题描述】:

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

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

这是我们尝试过的:

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

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

[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 将报告构建成功。我们该如何解决这个问题?

解决方案:

TeamCity 提供了一种称为Service Messages 的机制,可用于处理此类情况。 我已将构建脚本更新为如下所示:

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

因此,由于“编译失败”,TeamCity 会报告我的构建失败。

【问题讨论】:

  • GOTO OK 去哪儿了? %ERRORLEVEL% 是什么?

标签: visual-studio-2008 command-line teamcity teamcity-5.1


【解决方案1】:

参见Build Script Interaction with TeamCity 主题。

您可以通过以下方式报告构建日志的消息:

##teamcity[message text='<message text>' errorDetails='<error details>' status='<status value>']

地点:

  • status 属性可以采用以下值:NORMAL、WARNING、 失败,错误。默认值为 NORMAL。
  • 错误详情 仅当状态为 ERROR 时才使用属性,在其他情况下为 忽略。

如果此消息的状态为 ERROR 并且 “如果构建运行程序记录错误消息,则构建失败” 复选框是 检查构建配置常规设置页面。例如:

##teamcity[message text='Exception text' errorDetails='stack trace' status='ERROR']

2013 年 8 月 30 日更新:

从 TeamCity 7.1 开始,构建失败应改为使用 buildProblem 服务消息报告:

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

【讨论】:

  • 谢谢!通过使用 buildStatus 消息,我能够让事情正常工作。我将使用此信息更新原始帖子。
  • 这也适用于 powershell 脚本,例如echo "##teamcity[message text='oops' errorDetails='' status='ERROR']"
猜你喜欢
  • 2014-03-03
  • 1970-01-01
  • 2011-10-02
  • 2018-03-11
  • 1970-01-01
  • 2019-03-15
  • 2018-09-28
相关资源
最近更新 更多