ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject AW: ant return status
Date Fri, 16 Dec 2005 06:39:11 GMT
>> I'm charged with learning more about ant return status variables.  I 
>> have no clue where to start.  Links to documentation that 
>will help me 
>> understand it would be most welcome.  Pointing to specific 
>sections of 
>> documentation would be helpful.  To clarify my interest:  I am 
>> interested in capturing whether or not ant has successfully 
>completed 
>> execution or if there was a failure.
>
>The ant commandline script under windows (NT/XP/etc.) returns 
>either 0 or 1.
>A zero value indicates that the build was successful.  A value 
>of 1 indicates an error. Under Windows you can use the 
>ERRORLEVEL variable to test the result of invoking ant.  For example:
>
>  CALL :execute-my-ant-build
>  IF ERRORLEVEL 1 GOTO :exit
>
>  :execute-my-ant-build
>  PUSHD my-dir\my-subdir
>  CALL ant %*
>  POPD
>  GOTO :EOF
>
>  :exit
>  IF ERRORLEVEL 1 ECHO WOOPS, SOMETHING FAILED
>  GOTO :EOF
>
>Cheers, Steve.


If you use <fail> you could provide a level for your own using "status"
attribute. It´s passed to System.exit() which results (on windows) in
%ERRORLEVEL%.


Jan


Example:


build.xml
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----
<project default="check">
    <target name="check" depends="-c1,-c2"/>
    <target name="-c1" if="status">
        <fail status="${status}" message="Return-Code: ${status}"/>
    </target>
    <target name="-c2" unless="status">
        <echo>Alles ok</echo>
    </target>
</project>
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----




check.bat
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----
@echo off
setlocal

set arg=-Dstatus=%1
if "%1"=="" set arg=


call ant %arg% -quiet check
if %ERRORLEVEL% gtr 2 goto levelElse
goto level%ERRORLEVEL%

:level0
echo Suuper
goto end

:level1
echo na ja
goto end

:level2
echo hilfe
goto end

:levelElse
echo KATASTROPHE !!!
goto end



:end
endlocal
---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message