TeamCity 7.0.1命令行构建步骤和ERRORLEVEL

时间:2013-02-07 16:06:33

标签: teamcity teamcity-7.0

我的构建配置中有一个构建步骤,即跑步者类型"命令行",运行自定义脚本。

脚本正在执行Robocopy:

robocopy "%teamcity.build.workingDir%\Code" "\\target\d$\Web\Target Sites" /E /NP /LOG:robocopy.log

if ERRORLEVEL GEQ 4 (
"D:\blat.exe" "robocopy.log" -to me@me.com -f me@me.com -subject "Error during robocopy on TEAMCITY" -server mail.me.com
)

exit /B 0

Robocopy命令工作正常,但我一直收到一封电子邮件,并且在构建日志中我一直看到:

  

此时GEQ出人意料。

ERRORLEVEL检查由于某种原因不起作用?

我尝试了IF %ERRORLEVEL% GEQ但是这打破了我的构建,TeamCity希望我传递一个构建参数。

这是否仅作为"带有参数的可执行文件"?

干杯

2 个答案:

答案 0 :(得分:25)

尼尔,你可以试试escaping the percent sign

尝试IF %%ERRORLEVEL%% GEQ ...

答案 1 :(得分:0)

我刚遇到这个问题,并感谢@ John的回答。

以下是我提出的建议:

robocopy [from] [to] /MIR

REM http://ss64.com/nt/robocopy-exit.html
IF %%ERRORLEVEL%% EQU 0 (
   ECHO No errors occurred, and no copying was done; The source and destination directory trees are completely synchronized.
  EXIT 0
)
IF %%ERRORLEVEL%% EQU 1 (
  ECHO One or more files were copied successfully, new files have arrived.
  EXIT 0
)
 IF %%ERRORLEVEL%% EQU 2 (
  ECHO Some Extra files or directories were detected. No files were copied.
  EXIT 0
 ) 
IF %%ERRORLEVEL%% GEQ 3 (
  ECHO Robocopy Exit Codes: http://ss64.com/nt/robocopy-exit.html  
  EXIT %%ERRORLEVEL%%
)