2010-09-09 176 views
27

我們使用TeamCity的命令行構建運行器來調用bat文件。該bat文件通過調用Visual Studio 2008的「devenv.exe」構建我們的解決方案,然後執行單元測試並創建正確的文件夾結構。TeamCity命令行構建運行器:如何使構建失敗?

我們想要做的是停止執行bat文件,如果調用devenv失敗並使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將報告我作爲構建失敗,因爲一個「在編譯失敗」。

+1

「GOTO OK」去哪裏?什麼是%ERRORLEVEL%? – 2011-10-06 13:18:34

回答

21

請參閱Build Script Interaction with TeamCity主題。

您可以通過以下方式彙報生成日誌消息:

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

其中:

  • 的狀態屬性可採取以下值:正常,警告, 故障,錯誤。默認值是NORMAL。
  • 僅當狀態爲ERROR時才使用errorDetails 屬性,而在其他情況下則忽略 。

此消息未能構建的情況下,其狀態是錯誤和 「建設失敗如果錯誤信息是由編譯亞軍登錄」複選框被選中 構建配置常規設置頁面上。例如:

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

更新2013年8月30日:

作爲TeamCity的7。應該使用buildProblem服務消息來報告1構建失敗:

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

謝謝!我能夠通過使用buildStatus消息來獲得工作。我將使用此信息更新原始帖子。 – 2010-09-09 07:00:26

+3

這也適用於powershell腳本,例如'echo「## teamcity [message text ='oops'errorDetails =''status ='ERROR']」' – 2012-01-27 15:06:31

相關問題