Refactor IDs

Ant conditional failure execution failure

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 does not work for any reason (script.pl does not exist, etc.), the assembly will be successfully resolved. How to set conditional build success to the success of this executable?

+6
source share
3 answers

just add failonerror="true" to the exec element

+11
source

I assume this is an ant script and not an xsl target.

You can use the failifexecutionfails attribute of the exec task:

http://ant.apache.org/manual/Tasks/exec.html

Thus, if your execution fails for any reason, your assembly will also fail. By default, this value is true. You can also check the return code of your executable using attributes:

 failonerror 

and

 resultproperty 

eg.

 <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> 
+7
source

To crash immediately, use the failonerror attribute:

 <exec dir="${basedir}" executable="sh" failonerror="true"> <arg line="-c 'myscript'" /> </exec> 

To perform some other actions before the failure, save 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> 
+1
source

Source: https://habr.com/ru/post/899494/


All Articles