Chris,

I'm not sure this is something we should "fix". 

If we do this, then we should do it for both onsuccess and onfailure. We
then risk hiding the original build outcome.

Gert

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Chris
Lambrou
Sent: maandag 12 november 2007 16:53
To: nant-developers@lists.sourceforge.net
Subject: [nant-dev] Bug? <fail/> task doesn't work as expected when
calledwithin a nant.onsuccess target

Hi,

I recently posted an issue on the nant-users list, but I think the
underlying issue is one for this list. The problem is that the <fail/> task
doesn't cause NAnt to terminate with a non-zero exit-code when executed from
within a target defined by the nant.onsuccess property. I think that it
should always result in a non-zero exit code (with the possible exception of
when a BuildException is explicitly caught by the trycatch task from
nant-contrib).

The scenario is that I'm using CruiseControl.NET to run a NAnt script as
part of a continuous build process. There are two conditions under which
CCNET needs to consider the build a failure:

1. Fatal errors: Typically this would be a compilation error. This is
considered fatal, as my build script cannot proceed further. In this case,
the relevant NAnt task will fail, the BuildException causes NAnt to unwind
and it terminates with a non-zero exit-code. CCNET detects this exit code,
and considers the build to have failed.

2. Non-fatal errors: This is where a condition is detected that should
result in CCNET considering the build to be a failure, but no specific task
in the NAnt script actually fails, and the script can nonetheless proceed to
completion, whereby NAnt would normally terminate with an exit code of zero.
Typically, such a compilation error might be an FxCop rule violation, or a
unit-test failure.

In the case of non-fatal error, I'm trying to force the NAnt script to fail
using the technique illustrated in the following build script (attached),
that shows three different cases:

1. Case 1: This simply illustrates NAnt running successfully.
2. Case 2: This is the typical use of the <fail/> task to cause a fatal
build error.
3. Case 3: This is how I wish to deal with non-fatal errors. The "case3"
target modifies a property to indicate that a non-fatal error has occurred,
but script execution continues. After the rest of the script has completed,
the "on-success" target checks the "error-message" property, and tries to
<fail/> the build if a non-fatal error was detected.

    <project name="NAnt bug" xmlns="http://nant.sf.net/nant-all.xsd";>

        <property name="error-message" value=""/>
    
        <target name="case1">
            <echo message="This target should result in an exit-code that
indicates success."/> 
        </target>
    
        <target name="case2">
            <fail message="This target should result in a exit-code that
indicates failure."/>
        </target>
    
        <target name="case3">
            <echo message="This target should result in a exit-code that
indicates failure."/>
            <property name="error-message" value="Non-fatal error."/>
        </target>
    
        <property name="nant.onsuccess" value="on-success"/>
        <target name="on-success">
            <fail message="Failure forced"
if="${string::get-length(error-message) > 0}"/>
        </target>
    </project>



The following batch script can be used to run the three different cases:

    nant case1
    echo Error-level: expected 0, actual %errorlevel%
    nant case2
    echo Error-level: expected 1, actual %errorlevel%
    nant case3
    echo Error-level: expected 1, actual %errorlevel%



Cases 1 and 2 work just fine. Case 3 should display this,

    Error-level: expected 1, actual 1

but it actually displays this:

    Error-level: expected 1, actual 0


In case 3, because NAnt terminates with an exit code of zero, CCNET assumes
that the build was successful, when in fact I want CCNET to consider the
build a failure. It's my guess that the problem isn't specific to the
<fail/> task - NAnt is probably consuming any BuildException that may be
raised by the on-success task. I think that this is an error. If there's an
error in the on-success target, the build should fail, even when the main
execution of the build script was successful.


Chris

No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.503 / Virus Database: 269.15.30/1125 - Release Date: 11/11/2007
21:50
 
  


-------------------------------------------------------------------------
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-developers mailing list
nant-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-developers

Reply via email to