Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I let a teamcity command line build step pass if the exit code is not zero?

Tags:

teamcity

I have a command line 'custom script' build step involving robocopy. Unfortunately when robocopy is successful, it returns exit code 1 instead of the more common exit code 0. When it does this, it fails my teamcity build configuration.

How can I tell teamcity to fail the build if the exit code != 1 for this build step only? Can this be done? What about editing project-config.xml somehow?

like image 817
Isaac Bolinger Avatar asked Jan 23 '13 10:01

Isaac Bolinger


2 Answers

You can edit your script to ignore false negative, but keep real errors, as described in the robocopy documentation
Errorlevel 1, 2 and 3 are success.
So you can add that after your robocopy line in teamcity:

if %ERRORLEVEL% EQU 3 echo OKCOPY + XTRA & goto end
if %ERRORLEVEL% EQU 2 echo XTRA & goto end
if %ERRORLEVEL% EQU 1 echo OKCOPY & goto end
if %ERRORLEVEL% EQU 0 echo No Change & goto end
:end  

Or, more generic:

IF %%ERRORLEVEL%% LEQ 3 set errorlevel=0 
if %%errorlevel%% neq 0 exit /b %%errorlevel%%
like image 80
foxontherock Avatar answered Sep 21 '22 11:09

foxontherock


The Team City Custom Script step fails if the last command in it fails, i.e. has a non-zero exit code. You can therefore add an extra command that always succeeds after the RoboCopy command.

For example:

robocopy ...
echo "robocopy done. this will make the build step succeed always"
like image 41
Amnon Avatar answered Sep 24 '22 11:09

Amnon