首页 文章

TeamCity命令行构建运行器:如何使构建失败?

提问于
浏览
27

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

如果对devenv的调用失败并使TeamCity意识到构建失败,我们想要做的是停止执行bat文件 . 我们可以通过检查 ErrorLevel (如果构建失败,这是1)来捕获失败的devenv调用,并且我们可以在那时退出我们的bat文件 . 但 how can we tell to the TeamCity that the build failed

这是我们尝试过的:

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

Solution:

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

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

因此,TeamCity会因为“编译失败”而将我的构建报告为失败 .

1 回答

  • 21

    Build Script Interaction with TeamCity主题 .

    您可以通过以下方式报告构建日志的消息:## teamcity [message text ='<message text>'errorDetails ='<error details>'status ='<status value>']其中:status属性可能需要以下值:NORMAL,WARNING,FAILURE,ERROR . 默认值为NORMAL . 仅当status为ERROR时才使用errorDetails属性,在其他情况下将忽略该属性 . 如果状态为ERROR,则此消息将无法生成,并且在构建配置常规设置页面上选中“如果构建运行程序记录错误消息,则构建失败”复选框 . 例如:## teamcity [message text ='Exception text'errorDetails ='stack trace'status ='ERROR']

    Update 2013-08-30:

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

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

相关问题