使用sbt构建时检查错误级别

时间:2016-01-03 21:02:33

标签: windows batch-file cmd sbt errorlevel

我想编写一个windows .cmd脚本,将所有项目模块发布到本地存储库中。但我想先停止可能发生的错误。我正在检查%ERRORLEVEL%,但即使sbt publish-local命令因某些错误而失败,它也始终等于0。

@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

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:4)

试试这个:

@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

请注意,EnableDelayedExpansion不应包含以下内容,您应该在批处理中使用!而不是%