脚本而不会导致构建失败

脚本而不会导致构建失败

本文介绍了停止 ant 脚本而不会导致构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 ant 脚本中,我想在满足条件时退出(停止执行构建)而不会失败.我曾尝试使用:

In my ant script I want to exit (stop executing build) without failing when a condition is met. I have tried to use:

<if>
    <equals arg1="${variable1}" arg2="${variable2}" />
  <then>
    <fail status="0" message="No change, exit" />
  </then>
</if>

Ant 脚本有条件停止但构建失败.我想停止构建但没有错误.我在 Jenkins 中使用调用 Ant"步骤.

Ant script is stopped on condition but build is failed. I want to the build to be stopped but with no errors. I'm using "Invoke Ant" step in Jenkins.

谢谢.

推荐答案

我建议通过重新考虑您的方法来重构您的 ant 脚本.如果您通过满足某个条件时执行构建"而不是满足另一个条件时构建失败"来解决您的问题,那么实现起来会更容易:

I would suggest to refactor your ant script by reconsidering your approach. If you approach your problem with "execution of a build when a certain condition is met" instead of "failing the build if another condition is met" it is easier to implement:

<!-- add on top of your build file -->
<if>
    <equals arg1="${variable1}" arg2="${variable2}" />
  <then>
    <property name="runBuild" value="true"/>
  </then>
  <else>
    <property name="runBuild" value="false"/>
  </else>
</if>


<!-- add to the target that shall be executed conditionally -->
<target name="myTarget" if="${runBuild}">
...

<!-- exit message as separate target -->
<target name="exitTarget" unless="${runBuild}">
  <echo message="No Change, exit" />
</target>

这篇关于停止 ant 脚本而不会导致构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 13:14