KBEC-00066 - Propagating errors in Windows commands to an ElectricCommander job step outcome

Article ID:360033194671
1 minute readKnowledge base

Description

Steps using Windows CMD commands can return a successful exit code (0) even if individual commands within the step fail. Reason: the last command in the step determines the exit code.

Solution

Save the ERRORLEVEL of the command, perform the other operations, and then return the desired error level on exit:

ectool badcommand
set SAVED_ERRORLEVEL=%ERRORLEVEL%
echo Saved errorlevel is %SAVED_ERRORLEVEL%
rem Show that the errorlevel has been reset to 0
echo Current errorlevel is %ERRORLEVEL%
exit %SAVED_ERRORLEVEL%
This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.