What is the most efficient way of checking if an environment variable has been set prior to executing the rest of an Ant script?
Let's say my Ant script requires the environment variable "FOO" to be set. I got the following to work, but I was wondering whether there was a less convulated way of achieving the same result:
<property environment="env"/>
<property name="env.FOO" value=""/>
<target name="my-target">
<condition property="foo.found">
<not>
<equals arg1="${env.FOO}" arg2=""/>
</not>
</condition>
<fail unless="foo.found" message="FOO not set."/>
<!-- do stuff here that uses the FOO environment variable -->
</target>
Isn't this as simple as:
<property environment="env"/>
<fail unless="env.FOO" message="FOO not set."/>
and the other thing you can do (additional to David's) is use
<isset property="env.Foo"/> instead of <equals />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With