Mik*_*nen 27 teamcity command-line visual-studio-2008 teamcity-5.1
我们使用TeamCity的命令行构建运行器来调用bat文件.bat文件通过调用Visual Studio 2008的"devenv.exe"构建我们的解决方案,然后执行单元测试并创建正确的文件夹结构.
如果对devenv的调用失败并使TeamCity意识到构建失败,我们想要做的是停止执行bat文件.我们可以通过检查ErrorLevel(如果构建失败时为1)来捕获失败的devenv调用,并且我们可以在那时退出我们的bat文件.但是我们怎么能告诉TeamCity构建失败了呢?
这是我们尝试过的:
call "build.bat"
IF ERRORLEVEL 1 EXIT /B 1
Run Code Online (Sandbox Code Playgroud)
但是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
Run Code Online (Sandbox Code Playgroud)
因此,TeamCity将报告构建成功.我们该如何解决这个问题?
解:
TeamCity提供了一种称为服务消息的机制,可用于处理这种情况.我已将构建脚本更新为如下所示:
IF %ERRORLEVEL% == 0 GOTO OK
echo ##teamcity[buildStatus status='FAILURE' text='{build.status.text} in compilation']
EXIT /B 1
:OK
Run Code Online (Sandbox Code Playgroud)
因此,TeamCity会因为"编译失败"而将我的构建报告为失败.
Ser*_*oda 21
请参阅与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']
更新2013-08-30:
从TeamCity 7.1开始,应使用buildProblem服务消息报告构建失败:
##teamcity[buildProblem description='<description>' identity='<identity>']
Run Code Online (Sandbox Code Playgroud)