Issue
I am trying to invoke this code in jenkins
rem copy installation to output folder
set src="C:\code\EPMD\Installer\inno setup\Output"
set dst="c:/test_installs/Calibration/%version_name%"
call robocopy %src% %dst% /MIR /E /is /it
The code runs and works, creating a new file in the destination folder.
This makes robocopy return 1, as the documentation states.
Then, it calls exit 1
internally, and jenkins thinks the build has failed.
How can I "catch" that return value and not fail the build?
Solution
The robocopy
command uses the exit code (or ErrorLevel
) to indicate the result of the copying action, where a value less than 8
does not mean that errors occured; you could post-convert this ErrorLevel
:
rem /* Note the changed quotation, so the quotes do no longer become part of the variable values;
rem this does not change much in the situation at hand when you quote the values later then,
rem but it will simplify potential concatenation of multiple variable values a lot: */
set "src=C:\code\EPMD\Installer\inno setup\Output"
set "dst=c:/test_installs/Calibration/%version_name%"
rem // Now the values become quoted; regard that the superfluous `call` has been removed:
robocopy "%src%" "%dst%" /MIR /E /IS /IT
rem // This handles the exit code (`ErrorLevel`) returned by `robocopy` properly:
if ErrorLevel 8 (exit /B 1) else (exit /B 0)
If you do not want to immediately exit the batch script after robocopy
, you might just do this:
set "src=C:\code\EPMD\Installer\inno setup\Output"
set "dst=c:/test_installs/Calibration/%version_name%"
robocopy "%src%" "%dst%" /MIR /E /IS /IT
rem // Terminate the script in case `robocopy` failed:
if ErrorLevel 8 exit /B 1
rem // Here we land when case `robocopy` succeeded;
rem Do some further actions here...
rem ...
rem // Finally explicitly force a zero exit code:
exit /B 0
Answered By - aschipfl
Answer Checked By - Gilberto Lyons (JavaFixing Admin)