I want to write a windows .cmd
script that publishing all project modules into local repository. But I want to stop at first error that may be occur. I'm checking %ERRORLEVEL%
but it's always equals to 0 even if sbt publish-local
command fails with some error.
@echo on
@setlocal enabledelayedexpansions
set modules=^
sbt-common^
common^
for %%A in (%modules%) do (
echo ======================================
echo = PUBLISHING %%A =
echo ======================================
cd %%A
call sbt publish-local
echo %ERRORLEVEL% :: <- Always = 0
if ERRORLEVEL 1 goto error
)
:error
@endlocal
exit /B 1
Any help will be appreciated.
Try this:
@echo on
@setlocal EnableDelayedExpansion
set modules=^
sbt-common^
common^
for %%A in (%modules%) do (
echo ======================================
echo = PUBLISHING %%A =
echo ======================================
cd %%A
call sbt publish-local
echo !ERRORLEVEL!
if !ERRORLEVEL! geq 1 goto error
)
:error
@endlocal
exit /B 1
Note that EnableDelayedExpansion
should not have a following s, and you should use !
instead of %
inside parenthesis in batch.