maven构建失败时如何停止批量执行

问题描述 投票:0回答:2

我有一个批处理文件可以让我的生活变得轻松。

我想构建一个 Maven 项目,然后将发行版从目标文件夹复制到另一个文件夹,然后解压缩它们,然后执行一些复制替换说明。当代码没有问题时,这完全可以正常工作。

如果构建有任何问题并且构建失败,那么我想停止批处理执行。

我无法弄清楚。

::Kill all the java processs
taskkill /f /im "java.exe"

::Take the sprint number form the user
set /p sprintNumber=Enter the sprint number:%=%

:: Navigate to the code path
cd D:\Sprint-%sprintNumber%
call D:

:: Build the code

::@echo ###############BUILDING####################
::call mvn clean install

::cd ..

::Remove the distribution
IF EXIST "D:\Distribution\Sprint-%sprintNumber%\" (
    rmdir "D:\Distribution\Sprint-%sprintNumber%\" /s /q
)
::Few more instructions

如果 maven 安装失败,我想停止执行。请提供任何建议来完成此任务。

java maven batch-file
2个回答
8
投票

在构建命令之后的行添加类似的内容

if errorlevel 1 echo An error occurred & pause & goto :EOF

0
投票

您可以通过格式错误的

if
表达式来停止外部脚本执行:

实现:https://github.com/andry81/contools/tree/HEAD/Scripts/Tools/std/assert.bat

断言.bat

@echo off
@if 0 %*

build.bat

@echo off

if not 1 == 1 call assert.bat "test 1"
if not 2 == 3 call assert.bat "test 2"
if not 3 == 3 call assert.bat "test 3"
>bulid.bat
"test 2" was unexpected at this time.
© www.soinside.com 2019 - 2024. All rights reserved.