ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Leftwich <digi...@ix.net.au>
Subject Re: Is there any way to check if an environment variable is set?
Date Mon, 21 May 2001 00:43:37 GMT
At 03:31 AM 19-05-01, Bernhard Lenz wrote:
>Is there any way in ant to check if an environment variable is set and abort
>the build process with an error message in case the variable is not set?

If you use the environment version of the property tag i.e.

         <property environment="osEnv" />

you can access the environment variables as ${osEnv.ENV_VAR_NAME} and call 
fail if the required var is not present e.g.

     <!-- setup for initialization checks -->
     <target name="init.check.setup">
         <property environment="osEnv" />
     </target>

     <!-- check for required env var prior to doing anything -->
     <target name="init.check.env" depends="init.check.setup" 
unless="osEnv.ENV_VAR_NAME">
         <fail message="This build needs ENV_VAR_NAME set"/>
     </target>

Note there may be some case sensitivities depending on your os and 
environment does not work on all os'es. Searching the mailing list may help 
in sorting out any issues you have with it.

HTH

Robert



Mime
View raw message