I have the following ant target:
<target name="refactor-ids">
<echo>Refactor IDs</echo>
<exec executable="perl" dir="${basedir}">
<arg value="script.pl" />
<arg value="input.xml" />
</exec>
</target>
If the executable fails for any reason (script.pl doesnt exist, etc) the build will resolve as successful. How do I establish conditional build success upon the success of this executable?
just add failonerror="true"
to the exec element
I am assumng this is an ant script and not an xsl target.
You can use the attribute failifexecutionfails of the exec task :
http://ant.apache.org/manual/Tasks/exec.html
So if your execution fails for any reason your build will also fail. This is by default true. You can also check for the return code of your executable by using attributes :
failonerror
and
resultproperty
e.g.
<target name="refactor-ids">
<echo>Refactor IDs</echo>
<exec executable="perl" dir="${basedir}" failonerror="false" resultproperty="return.code">
<arg value="script.pl" />
<arg value="input.xml" />
</exec>
<fail>
<condition>
<equals arg1="-1" arg2="${return.code}"/>
</condition>
</fail>
</target>
To fail immediately, use the failonerror attribute:
<exec dir="${basedir}" executable="sh" failonerror="true">
<arg line="-c 'myscript'" />
</exec>
To perform some other action before failing, store the exit code in the resultproperty attribute. Typically, 0 indicates success, and 1 or higher indicates an error:
<exec dir="${basedir}" executable="sh" failonerror="false" resultproperty="exitStatusCode">
<arg line="-c 'myscript'" />
</exec>
<!-- Do some other stuff before failing -->
<fail>
<condition>
<not>
<equals arg1="0" arg2="${exitStatusCode}"/>
</not>
</condition>
</fail>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With