Reputation: 7388
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?
Upvotes: 12
Views: 22706
Reputation: 1559
In Linux bash script I've fixed it by adding next line to the end of my script:
exit $?
This will return status code from last command when exit from bash.
And TeamCity's build step will fail like any other step.
See more details about the syntax here.
Upvotes: 0
Reputation: 1841
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%%
Upvotes: 1
Reputation: 2320
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"
Upvotes: 6
Reputation: 2762
There's two ways:
In that Build Configuration, go to the Build Failure Conditions step. Look for the heading Fail build if: . The first checkbox is "build process exit code is not zero". Make sure that sucker isn't checked.
When you run robocopy, check the result of the call to robocopy. You can explicitly exit 0
from inside the script if robocopy works, or do something else. This is necessary if you need to fail the build upon other conditions (e.g., first exit 1 if the source folder doesn't exist, then run robocopy, then send a message if robocopy is successful).
Upvotes: 18