I've got the following problem: My project has a make_all.bat
file which executes several builds like this:
call make_first_component.bat
if %ERRORLEVEL% gtr 0 ( exit /b %ERRORLEVEL% )
call make_second_component.bat
if %ERRORLEVEL% gtr 0 ( exit /b %ERRORLEVEL% )
There are no additional lines in that script (except for echo
commands).
Now when I call that script manually by double clicking, or from the command line, and make_first_component.bat does something like exit /b 1
, the make_all.bat
quits as intended.
When I call the script from a jenkins job (code below), make_all.bat
continues with the second component even if the first component fails.
If I then log onto the build slave with this behaviour and manually start the batch file there, it quits if the first component fails.
So what does jenkins do that breaks the %ERRORLEVEL%
concept?
PS: I've tried doing setlocal enabledelayedexpansion
and then using !ERRORLEVEL!
, but it is always 0.
Note: The jenkins job has an "Execute Windows batch command" step which looks like this:
cd %WORKSPACE%\src\bat
echo Setting up Visual Studio environment
call "%VS120COMNTOOLS%..\..\VC\vcvarsall.bat" amd64
echo Building Project
call make_all.bat
if %ERRORLEVEL% gtr 0 ( exit /b %ERRORLEVEL% )
(That is the complete step)
This effect would occur when ERRORLEVEL is overwritten.
Sample
set errorlevel=0
cd ThisDoesntExist
echo %errorlevel%
set "errorlevel="
echo %errorlevel%
It outputs
0
1
Conclusion: With set "errorlevel="
you can restore the normal %ERRORLEVEL%
behaviour
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With