【问题标题】:Condition in Ant not working properlyAnt 中的条件无法正常工作
【发布时间】:2016-05-18 06:47:19
【问题描述】:

我正在 Ant 中执行一项任务,该任务测试服务器是停止还是运行,如果服务器停止,Ant 任务将失败并发送电子邮件。问题是我的状态不能正常工作,无论服务器停止还是运行,任务总是很好。

这是我的条件的代码:

<condition property="check" value="true" >
<or>
<equals arg1="${state}" arg2="STOPPED" />
<equals arg1="${state}" arg2="STOPPING" />
</or>
</condition>
<fail if="${check}" message="Server stopped"/>

变量 state 可以有下一个值:STOPPED、STOPPING 或 STARTED(我之前检查过该值是否正确)。正如我所说,即使 state = STOPPED 或 state = STOPPING,也永远不会设置属性检查,所以我的任务总是成功的。

我试过在equals中使用forcestring和区分大小写,我也试过了:

<fail if="check" message="Server stopped"/>

但条件仍然不起作用。

关于如何解决这个问题并使其发挥作用的任何建议或想法?

谢谢。

【问题讨论】:

  • &lt;fail if="check" message="Server stopped"/&gt;绝对是&lt;fail&gt;的正确使用方式。如果你把&lt;echo&gt;check: ${check}&lt;/echo&gt; 放在&lt;fail&gt; 之前,输出是什么?

标签: jenkins ant


【解决方案1】:

试试这个:

<fail message="Server stopped">
   <condition>
     <or>
       <equals arg1="${state}" arg2="STOPPED" />
       <equals arg1="${state}" arg2="STOPPING" />
     </or>
   </condition>
</fail>

【讨论】:

    【解决方案2】:

    试试:

    <target name="server_stopped" if="check">
            <fail message="Server stopped"/>
    </target>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-27
      • 1970-01-01
      • 2014-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-16
      相关资源
      最近更新 更多