Search code examples
buildnantconditional-statements

Clean up after nant build failures


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?


Solution

  • 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" />