我想我的构建脚本以正确的解放和发展环境的行为。

有关此我想在蚂蚁来定义属性,把它称为(例如)fileTargetName

fileTargetName会得到它从环境变量RELEASE_VER价值,如果它是可用的,如果它不存在,它会得到的默认值的开发

与蚂蚁<condition><value></condition><property>帮助得到它的工作理解。

有帮助吗?

解决方案

如何获得蚂蚁文档一个例子环境变量到属性:

<property environment="env"/>
<echo message="Number of Processors = ${env.NUMBER_OF_PROCESSORS}"/>
<echo message="ANT_HOME is set to = ${env.ANT_HOME}"/>

在你的情况,你可以使用${env.RELEASE_VER}

然后,对于该条件部分,文档 说,有三个可能的属性:

Attribute  Description                                             Required 
property   The name of the property to set.                        Yes 
value      The value to set the property to. Defaults to "true".   No 
else       The value to set the property to if the condition       No
           evaluates to false. By default the property will
           remain unset. Since Ant 1.6.3

将其组合在一起:

<property environment="env"/>
<condition property="fileTargetName" value="${env.RELEASE_VER}" else="dev">
    <isset property="env.RELEASE_VER" />
</condition>

其他提示

您不需要使用<condition>这一点。在Ant属性是不变,所以你可以用这样的:

<property environment="env"/>
<property name="env.RELEASE_VER" value="dev"/>

如果该RELEASE_VER环境变量设置,则该属性将得到从环境和第二<property>声明不会有任何影响它的价值。否则,属性将是第一个语句之后未设置,并且所述第二声明将其值设置为"dev"

我敢肯定有比这更简单的方法,但如何:

<project name="example" default="show-props">

    <property environment="env" />

    <condition property="fileTargetName" value="${env.RELEASE_VER}">
        <isset property="env.RELEASE_VER" />
    </condition>

    <condition property="fileTargetName" value="dev">
        <not>
            <isset property="env.RELEASE_VER" />
        </not>
    </condition>

    <target name="show-props">
        <echo>property is ${fileTargetName}</echo>
    </target>

</project>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top