从环境中定义 ant 属性并使用默认值
我希望我的构建脚本能够在发布和开发环境中正常运行。
为此,我想在 ant 中定义一个属性,调用它(例如) fileTargetName
fileTargetName
将从环境变量 RELEASE_VER
中获取它的值,如果它可用,如果不可用,它将获取默认值 dev
Help with ant
&
使其正常工作值得赞赏。
I would like my build script to act properly for release and development environments.
For this I would like to define a property in ant, call it (e.g.) fileTargetName
fileTargetName
will get it's value from the environment variable RELEASE_VER
if it's available, if it is not available it will get the default value of dev
Help with ant <condition><value></condition>
& <property>
to get it working is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Ant 文档中有关如何获取环境变量的示例进入属性:
在您的情况下,您将使用
${env.RELEASE_VER}
。然后对于条件部分,文档这里说有三个可能的属性:
把它放在一起:
An example from the Ant documentation of how to get an environment variable into a property:
In your case, you would use
${env.RELEASE_VER}
.Then for the conditional part, the documentation here says that there are three possible attributes:
Putting it together:
您不需要为此使用
。 Ant 中的属性是 不可变,因此您可以使用它:如果
RELEASE_VER
环境变量设置后,属性将从环境中获取其值,第二个
语句将不起作用。 否则,该属性将在第一个语句之后取消设置,第二个语句将其值设置为“dev”
。You don't need to use a
<condition>
for this. Properties in Ant are immutable, so you can just use this:If the
RELEASE_VER
environment variable is set, then the property will get its value from the environment and the second<property>
statement will have no effect. Otherwise, the property will be unset after the first statement, and the second statement will set its value to"dev"
.我确信有比这更简单的方法,但是怎么样:
I'm sure there are easier ways than this, but how about: