views:

27

answers:

2

I'm looking for my nant build script to be able to clean up after itself if a build goes wrong. I'm looking for something resembling the following execution:

Target= Software.Build

Target= Software.Build.Success *(depends on Software.Build succeeding)*

Target= Software.Build.Failed

I am looking for a solution that if the Software.Build target fails then Software.Build.Failed will be executed e.g. to e-mail someone that the build failed in some way, otherwise Software.Build.Success will be run to allow the build script to continue.

Is this even possible with nant? If so, could anyone point me to a suitable article/solution?

+1  A: 

NAntContrib has a trycatch task:

<trycatch>
  <try>
    <call target="Software.Build" />
  </try>
  <catch>
    <call target="Software.Build.Failed" />
    <fail message="build failed" />
  </catch>
  <finally>
    <!-- execute everything that doesn't depend on success or failure -->
  </finally>
</trycatch>
<call target="Software.Build.Success" />
The Chairman
Thanks for the succinct example! I looked into writing my own custom Task to allow me to implement a 'callOnError' property to help simplify the build scripts, but as this works there is probably no need to go overboard on a neater solution!
TK
A: 

Or if you have global data to be cleaned up, you can use the NAnt OnFailure event.

<property name="nant.onfailure" value="failure" />
<target name="failure">
    <!-- Put your cleaning code in here -->
</target>
Dennis