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 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.
Thanks.
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:
Internally
<fail>
throws aBuildException
to fail the build process, so, as long as you are using this task, you will get the ant build exit with errors.Personally I don't know if there is any other task to "normally" exit the build, but writing one by yourself is not hard at all.
Writing a task which executes the following code should work...
Use builtin (since JDK 6) javascript engine, no additional libraries (antcontrib .. etc.) needed !
1. Java System.exit()
you may get a BUILD FAILED when running in Eclipse : BUILD FAILED javax.script.ScriptException: sun.org.mozilla.javascript.internal.WrappedException: Wrapped org.eclipse.ant.internal.launching.remote.AntSecurityException => then use Ant api instead
2. Ant api
Output Eclipse, no BUILD SUCCESSFUL is printed :
Output Console, BUILD SUCCESSFUL is printed 2 times :
Wrap in a macrodef for reuse, f.e. :
Examples
output :
output :