14

I have a build step in my build configuration thats runner type "Command Line", running a custom script.

The script is executing 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

The Robocopy command is working fine but I keep getting an email and in the build log I keep seeing:

GEQ was unexpected at this time.

The ERRORLEVEL check isn't working for some reason?

I tried IF %ERRORLEVEL% GEQ but this breaks my build has TeamCity expects me to pass a build parameter.

Does this only work as an "Executable with parameters"?

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Neil
  • 2,688
  • 1
  • 23
  • 32

2 Answers2

29

Neil, you might try escaping the percent sign.

Try IF %%ERRORLEVEL%% GEQ ...

John Hoerr
  • 7,955
  • 2
  • 30
  • 40
  • Cheers! This is pretty fortuitous -- some folks I work with were just yesterday trying to figure out how to get robocopy to return a different exit code to TeamCity. :) – John Hoerr Feb 07 '13 at 17:30
  • Lol - uncanny, I've just done the same thing. Ended up with EXIT /B 0. Is that how you guys did it? – Neil Feb 07 '13 at 19:59
  • Well, at the time we couldn't find any guidance Stackoverflow, so we gave up. I'm forwarding this thread to them though. – John Hoerr Feb 07 '13 at 20:01
  • Using TeamCity 8.0.5, I actually had to enter %%%% in the TeamCity Command line runner interface, which became %% in the temporary .cmd file created - i.e. escape by using four %s per % in the command. – Chris B Mar 05 '14 at 10:33
0

I've just run into this problem, and appreciate @John's answer.

Here is what I came up with:

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%%
)
David Alpert
  • 3,161
  • 1
  • 23
  • 19