Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins - simply robocopy in Jenkins finishes marks build with failure

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

like image 209
user2860244 Avatar asked Oct 08 '13 20:10

user2860244


2 Answers

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.

like image 128
Robert Fey Avatar answered Oct 27 '22 19:10

Robert Fey


Jenkins marks a build as failed when the exist code of a batch script is not 0. If robocopy is the last command in your script, the robocopy exit code will be taken.

Robocopy does not adhere to the standard that an exit code other then 0 means a failed build. You need to evaluate the robocopy exit code and end your script with exit 0 or exit 1 depending on the success of robocopy.

Have a look at the robocopy exit codes.

like image 24
Peter Schuetze Avatar answered Oct 27 '22 20:10

Peter Schuetze