TeamCity 7.0.1 command line build step and ERRORLEVEL
Asked Answered
C

2

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 [email protected] -f [email protected] -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"?

Codd answered 7/2, 2013 at 16:6 Comment(0)
L
29

Neil, you might try escaping the percent sign.

Try IF %%ERRORLEVEL%% GEQ ...

Lazurite answered 7/2, 2013 at 16:34 Comment(4)
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. :)Lazurite
Lol - uncanny, I've just done the same thing. Ended up with EXIT /B 0. Is that how you guys did it?Codd
Well, at the time we couldn't find any guidance Stackoverflow, so we gave up. I'm forwarding this thread to them though.Lazurite
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.Holliman
C
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%%
)
Cetology answered 10/4, 2015 at 19:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.