Freiheit
Freiheit

Reputation: 8757

Continue executing ant script if one task fails

I have an Ant script which runs tests then deploys my application to a QA server. To deploy the application it first calls sun-appserv undeploy, for various reasons the application may or may not be deployed. If the application is not deployed then undeploy fails and the whole script halts.

Is there some way that I can tolerate a failure on one task, log it, and let the rest of the script run?

Upvotes: 4

Views: 6543

Answers (3)

Adam Bruss
Adam Bruss

Reputation: 1674

AntContrib try catch:

<trycatch>
<try>
   <!-- do deployment getting return code -->
</try>
<catch>
   <!-- echo the return code with a message -->
</catch>
</trycatch>

The exec task has a failonerror attribute which you can set to false to keep going.

Upvotes: 6

JShumaker
JShumaker

Reputation: 300

I was looking for something similar to this and found an alternative method that is useful if you want to run a lot of tasks that have no dependency on each other and you want to know if all 5 of them fail without having to fix the first one.

Enclose all the tasks in a parallel task with threadCount set to 1. It's definitely a mis-use of the parallel task but accomplishes my goal:

<parallel threadCount="1">
    <fail message="fail 1"/>
    <fail message="fail 2"/>
    <echo message="Success"/>
    <fail message="fail 3"/>
</parallel>

Running this in a target gives this for output:

test:
     [echo] Success

BUILD FAILED
C:\test\build.xml:5:
fail 1
fail 2
fail 3

Total time: 0 seconds

Upvotes: 2

Derek Prior
Derek Prior

Reputation: 3507

See the -keep-going option documented here

Upvotes: 0

Related Questions