Hi,
 
I'm using NAnt as part of a continuous build process managed by 
CruiseControl.NET. CCNET determines whether or not a build is a success or a 
failure on the basis of the exit code of the NAnt process that carries out the 
build. If my NAnt build script fails to execute any tasks (e.g. if any of my 
solutions don't compile), then NAnt terminates with a non-zero exit code - 
that's all well and good, as CCNET recognises this as a build failure. However, 
I also want to explicitly cause a build failure even if all the NAnt tasks 
execute successfully. For example, if there are any NUnit tests failures or 
FxCop rule violations, the NAnt script won't actually fail (because the NUnit 
and FxCop tasks executed successfully). In order to cause the build to fail 
when such non-fatal build errors are encountered, I have added a nant.onsuccess 
target that executes a <fail/> task if any such errors were detected.
 
The main thrust of this technique is illustrated by the following cut-down 
build script:
 
<project default="default">
    <property name="non-fatal-errors" value=""/>
 
    <target name="default">
        ... The main build work happens in here. If any non-fatal errors are 
detected during the build,
            appropriate error messages are appended to the non-fatal-errors 
property ...
    </target>
 
    <property name="nant.onsuccess" value="on-success"/>
 
    <target name="on-success">
        <fail message="Non-fatal build errors detected:${non-fatal-errors}" 
if="${string::get-length(non-fatal-errors) > 0}"/>
    </target>
</project>
 
If the NAnt script succeeds, the on-success task runs and tries to explicitly 
cause a build failure. If the <fail/> task is called anywhere from within a 
'normal' target, a BuildException is raised and NAnt terminates with a non-zero 
exit code. However, when a <fail/> task is called from within a 
'nant.onsuccess' task, NAnt doesn't terminate with a non-zero exit-code.
 
I've managed to work around this by modifying the on-success target to write 
the non-fatal-error property to a file on disk if it's non-empty
 
<echo file="error.txt" message="Non-fatal build errors 
detected:${non-fatal-errors}" if="${string::get-length(non-fatal-errors) > 0}"/>
 
and I use a bootsrap NAnt script to first call my main script and then fail if 
the main script wrote an error file. This is a rather inelegant solution - it 
would be much better if the <fail/> task always caused NAnt to fail, regardless 
of which target it executes in. Should the current behaviour be considered a 
bug, and does anyone have a more elegant solution to this problem?
 
Regards,
 
Chris

No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.503 / Virus Database: 269.15.26/1119 - Release Date: 08/11/2007 
17:55
 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to