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?
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%%
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With