Loops Ant-在循环中调用目标一次
我有一个公共build.xml文件,其中包含我的大多数目标。 有两个附属生成文件导入公共文件。卫星之间的区别在于,其中一个将运行公共目标一次,而另一个具有foreach ant contrib任务,该任务在子文件夹中循环,并在每个子文件夹中运行公共目标一次 公共文件中我的一个目标提示用户选择要发布到的区域(dev或qa)。 对于运行一次的卫星构建,这很好。 对于循环卫星构建,每个子文件夹都会向用户显示提示,但它们都会转到同一发布区域,因此我只需要询问一次此提示 简单的解决方案是将“选择区域”目标移动到每个附属构建文件,使其只运行一次,即,它位于循环之外。 我很想知道是否有更干净的方法 我最初的想法是在循环卫星构建(使用ant任务)中调用循环外的目标并设置属性。然后,我会在公共构建文件中的selectarea目标中添加一个“除非”属性,用于检查ant任务中设置的属性是否已设置。 据我估计,这将意味着非循环构建运行selectarea目标,因为属性尚未设置(它确实设置了)。 循环附属构建运行目标(使用ant任务),但当它循环到公共构建文件并命中选择区域目标时,它仍然运行该目标,即使已设置属性并且选择区域目标具有要检查的除非属性 示例代码如下: 从通用构建中提取Loops Ant-在循环中调用目标一次,loops,ant,ant-contrib,Loops,Ant,Ant Contrib,我有一个公共build.xml文件,其中包含我的大多数目标。 有两个附属生成文件导入公共文件。卫星之间的区别在于,其中一个将运行公共目标一次,而另一个具有foreach ant contrib任务,该任务在子文件夹中循环,并在每个子文件夹中运行公共目标一次 公共文件中我的一个目标提示用户选择要发布到的区域(dev或qa)。 对于运行一次的卫星构建,这很好。 对于循环卫星构建,每个子文件夹都会向用户显示提示,但它们都会转到同一发布区域,因此我只需要询问一次此提示 简单的解决方案是将“选择区域”目标
<target name="select-area" unless="area.selected" description="prompts user what area to deploy to and validates response">
<input message="Which area do you want to deploy to?" validargs="dev,qa" addproperty="deploy.to" />
...
</target>
...
循环卫星构建文件
<project name="run-build-file-multi" default="loop-brands">
<import file="../../../common/builds/newbuild.xml"/>
<ant antfile="${ant.file.common} target="select-area">
<property name="area.selected" value="yes" />
</ant>
<target name="loop-brands" depends="select-area" description="loops through each brand folder found in branch folder">
<foreach target="end-confirmation" param="current.brand" inheritall="true">
<path>
<dirset dir=".">
<include name="*"/>
</dirset>
</path>
</foreach>
</target>
</project>
这似乎是错误的:
<target name="select-area" unless="area.selected" description="prompts user what area to deploy to and validates response">
<input message="Which area do you want to deploy to?" validargs="dev,qa" addproperty="deploy.to" />
应该是
<target name="select-area" unless="deploy.to" description="prompts user what area to deploy to and validates response">
<input message="Which area do you want to deploy to?" validargs="dev,qa" addproperty="deploy.to" />
i、 e.除非使用与输入相同的变量,否则当变量设置一次时,应保持不变
或者,在两个构建脚本中,让脚本在开始时调用select area
一次(因此这两个脚本中的代码相同),然后在递归构建中启动循环。这似乎是错误的:
<target name="select-area" unless="area.selected" description="prompts user what area to deploy to and validates response">
<input message="Which area do you want to deploy to?" validargs="dev,qa" addproperty="deploy.to" />
应该是
<target name="select-area" unless="deploy.to" description="prompts user what area to deploy to and validates response">
<input message="Which area do you want to deploy to?" validargs="dev,qa" addproperty="deploy.to" />
i、 e.除非使用与输入相同的变量,否则当变量设置一次时,应保持不变
或者,在两个构建脚本中,让脚本在开始时调用select area
一次(因此这两个脚本中的代码都相同),然后在递归构建中启动循环。谢谢Aaron,现在我看到了答案。很好用!谢谢,亚伦,现在我明白答案了。很好用!