bat脚本实现Linux set -e 功能

 

在一个发布脚本中,进行realse操作可能需要如下几个步骤:

 

1. 调用build工具进行build

2. 使用SSH工具上传build出的jar包

3. 使用SSH工具向远程主机发布重启服务的命令

 

上述任何环节出错,则后续动作再执行已无意义,所以整个脚本应该停止执行,这种处理可以使用以下命令方式:

call 第三方脚本或程序1

if "%errorlevel%"=="1" goto :end

call 第三方脚本或程序2

if "%errorlevel%"=="1" goto :end

 

示例代码

@echo off

set profile=%1

if "%2"=="release" goto release

rem #######################################################################################

:release

echo.
echo ***************************************************************************************
echo BUILD ALL MODULES...
echo ***************************************************************************************

call mvn install -DskipTests=true -P%profile%
if "%errorlevel%"=="1" goto :releasefailed

echo.
echo ***************************************************************************************
echo DEPLOY CORE MODULE...
echo ***************************************************************************************

call its-core\target\classes\core-dev-tool.bat deploy
if "%errorlevel%"=="1" goto :releasefailed

echo.
echo ***************************************************************************************
echo DEPLOY CLIENT MODULE...
echo ***************************************************************************************

call its-client\target\classes\client-dev-tool.bat deploy
if "%errorlevel%"=="1" goto :releasefailed

echo.
echo ***************************************************************************************
echo DEPLOY SERVER MODULE...
echo ***************************************************************************************

call its-server\target\classes\server-dev-tool.bat deploy
if "%errorlevel%"=="1" goto :releasefailed

echo.
echo ***************************************************************************************
echo DEPLOY SDK MODULE...
echo ***************************************************************************************

call its-sdk\target\classes\sdk-dev-tool.bat deploy
if "%errorlevel%"=="1" goto :releasefailed

echo.
echo ***************************************************************************************
echo RESTART HBASE ...
echo ***************************************************************************************

call its-server\target\classes\server-dev-tool.bat restart-hbase
if "%errorlevel%"=="1" goto :releasefailed
goto releasesuccess

rem #######################################################################################

:releasesuccess
echo.
echo.
echo ***************************************************************************************
echo RELEASE SUCCESS!!
echo ***************************************************************************************
goto end

:releasefailed
echo.
echo.
echo ***************************************************************************************
echo RELEASE FAILED!!
echo ***************************************************************************************
goto end

:end

 

https://www.cnblogs.com/zhangjianbin/p/6286730.html

posted @ 2020-08-18 15:25  ascertain  阅读(420)  评论(0编辑  收藏  举报