You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Robert Leftwich <di...@ix.net.au> on 2001/05/21 02:43:37 UTC

Re: Is there any way to check if an environment variable is set?

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



Is there a way to do sed-style inline editing?

Posted by Mark Jaffe <mj...@eturn.com>.
Here's the issue. Our release standards are now being violated since I
switched to Ant for deployment of the builds. The former build-meister did
the main build manually, then created a folder on a shared machine to which
he copied the build results. Now I have a distribution mechanism in the
build script, but it does not do a similar-enough function. The old builds
were copied into a folder named "MMDD-HHMM" (where MMDD is the two-digit
month + two-digit day, and HHMM is the hours & minutes stuff.) Now I get a
folder called "20010521-HHMM" but I wondered if I could scriptually edit
this down to the old format.