Jenkins - simply robocopy in Jenkins finishes marks build with failure

user2860244 picture user2860244 · Oct 8, 2013 · Viewed 13.8k times · Source

I have a simply windows batch command (robocopy) that returns zero errors but is always marked as a failure in Jenkins. I would like to know why?

D:\Jenkins\jobs\Jenkins Config Backup\workspace>exit 1 Build step 'Execute Windows batch command' marked build as failure Finished: FAILURE

Answer

Robert Fey picture Robert Fey · Nov 27, 2014

robocopy returns a bit map

For details see here: http://ss64.com/nt/robocopy-exit.html

In summary: All exit codes up to '3' are fine.

This is the batch file code I usually use:

set SOURCE= ...
set DESTINATION= ...

robocopy /MIR %SOURCE% %DESTINATION%
@echo robocopy exit code: %ERRORLEVEL%
@if %ERRORLEVEL% GTR 3 ( echo robocopy ERROR )
@if %ERRORLEVEL% GTR 3 ( exit %ERRORLEVEL% )
@set ERRORLEVEL=0

You could also do a "goto" and not exit.