exec maven插件:退出代码
exec maven plugin: exit code
我有以下插件到 运行 一个 .sh
脚本:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>deploy-bundles</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/deploy.sh</executable>
<successCodes>
<successCode>0</successCode> <-- Not working
</successCodes>
</configuration>
</execution>
</executions>
</plugin>
将一些文件夹和文件复制到特定位置。有用。但是,为了以防万一,我想要一个出错时失败的机制。我的 .sh
脚本中已经有 set -e
命令,但我也想要一个 maven 解决方案。听说有个叫successCodes
的tag,我试着收下了。但到目前为止还没有运气。有人可以指出正确的做法吗?
编辑: 我的 .sh
脚本如下所示:
cp ../template/config.properties $component/conf
cp ../../runtime/group1/group1.mw/conf/log4j.xml $component/conf
# if the component is planning, create an additional folder called plans
if [[ $component == *".planning"* ]]
then
mkdir -p $component/plans
# copy all the plans here
cp ../../mission.planning/plans/* $component/plans
fi
如果这些 folders/files 不存在,预计会失败。因此,作为测试,我手动更改上面的路径并期望它失败。它确实使执行过程失败并告诉我错误(因为我在 .sh
脚本中有 set -e
命令),但是 Maven 报告为 "success".
这不是 Exec Maven 插件的问题,而是 Shell 脚本中退出代码处理的问题。
successCodes
参数在可执行文件的退出代码不同于 0 的情况下很有用 "successful execution":
Exit codes to be resolved as successful execution for non-compliant applications (applications not returning 0 for success).
The default behaviour是认为exit code为0执行成功,其他都认为执行失败,此时插件将构建失败。
在您的 Shell 脚本中,您有多个命令,each of which has its own exit code. Without any extra handling, the exit code of the script itself, as a whole, is the exit code of the last command. Therefore, even if one of the command failed (so its exit code is not zero) a successful command after that will reset the script exit code to 0. You can test that by invoking the script on the command line outside of Maven, and echo the $?
variable, which contains the exit code。
因此,您需要测试每个调用的命令的退出代码,这些命令可能会在您的 Shell 中失败。 (您也可以使用 a bit of arithmetic 来累积每个退出代码。)
我有以下插件到 运行 一个 .sh
脚本:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>deploy-bundles</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/deploy.sh</executable>
<successCodes>
<successCode>0</successCode> <-- Not working
</successCodes>
</configuration>
</execution>
</executions>
</plugin>
将一些文件夹和文件复制到特定位置。有用。但是,为了以防万一,我想要一个出错时失败的机制。我的 .sh
脚本中已经有 set -e
命令,但我也想要一个 maven 解决方案。听说有个叫successCodes
的tag,我试着收下了。但到目前为止还没有运气。有人可以指出正确的做法吗?
编辑: 我的 .sh
脚本如下所示:
cp ../template/config.properties $component/conf
cp ../../runtime/group1/group1.mw/conf/log4j.xml $component/conf
# if the component is planning, create an additional folder called plans
if [[ $component == *".planning"* ]]
then
mkdir -p $component/plans
# copy all the plans here
cp ../../mission.planning/plans/* $component/plans
fi
如果这些 folders/files 不存在,预计会失败。因此,作为测试,我手动更改上面的路径并期望它失败。它确实使执行过程失败并告诉我错误(因为我在 .sh
脚本中有 set -e
命令),但是 Maven 报告为 "success".
这不是 Exec Maven 插件的问题,而是 Shell 脚本中退出代码处理的问题。
successCodes
参数在可执行文件的退出代码不同于 0 的情况下很有用 "successful execution":
Exit codes to be resolved as successful execution for non-compliant applications (applications not returning 0 for success).
The default behaviour是认为exit code为0执行成功,其他都认为执行失败,此时插件将构建失败。
在您的 Shell 脚本中,您有多个命令,each of which has its own exit code. Without any extra handling, the exit code of the script itself, as a whole, is the exit code of the last command. Therefore, even if one of the command failed (so its exit code is not zero) a successful command after that will reset the script exit code to 0. You can test that by invoking the script on the command line outside of Maven, and echo the $?
variable, which contains the exit code。
因此,您需要测试每个调用的命令的退出代码,这些命令可能会在您的 Shell 中失败。 (您也可以使用 a bit of arithmetic 来累积每个退出代码。)