我尝试使用一个包含两个目标的脚本部署多个系统。当一个系统无法部署时,我想停止整个脚本并失败。
Player
问题是条件正确评估并且消息"我应该在这里失败!" 被打印,但构建不会失败并继续部署下一步系统
变量 $ {stop_execution_on_fail} 提供给脚本,并包含应该使整个构建失败的系统列表(而不是部署其余系统)。
有时,在部署了几个内存不足的系统后,构建失败。
<target name="deploy_all">
<for list="${systems}" param="system" delimiter="," parallel="false" threadCount="1" trim="true">
<sequential>
<antcall target="deploy_one_system">
<param name="system" value="@{system}" />
</antcall>
</sequential>
</for>
</target>
<target name="deploy_one_system">
<trycatch property="error_system">
<try>
<!-- deployment -->
<!-- Deep in other targets, there's <fail> -->
</try>
<catch>
<echo>Error during deployment of ${system}:</echo>
<echo>${error_system}</echo>
<!-- print logs, errors, cleanup -->
<if>
<contains string="${stop_execution_on_fail}" substring="${system}" />
<then>
<echo message="I should fail here!" />
<fail message="Error occured during deploying ${system}."/>
</then>
</if>
</catch>
</trycatch>
</target>
我正在运行Jenkins 1.642.1,JDK 1.8.0_74和Ant 1.9.2。
有什么想法吗?
编辑(基于pczeus&#39;评论):打印以下内容(不要介意时间戳,我是从其他版本中获取的):
17:07:03 deploy.xml:900:
17:07:03 The following error occurred while executing this line:
17:07:03 deploy.xml:908: The following error occurred while executing this line:
17:07:03 deploy.xml:802: Error occured during deploying system1.
17:07:03 The following error occurred while executing this line:
17:07:03 deploy.xml:908: The following error occurred while executing this line:
17:07:03 deploy.xml:802: Error occured during deploying system2.
17:07:03 The following error occurred while executing this line:
17:07:03 deploy.xml:908: The following error occurred while executing this line:
17:07:03 deploy.xml:802: Error occured during deploying system3.
17:07:03 The following error occurred while executing this line:
17:07:03 deploy.xml:908: The following error occurred while executing this line:
17:07:03 deploy.xml:4: java.lang.OutOfMemoryError: PermGen space
17:07:03 The following error occurred while executing this line:
17:07:03 deploy.xml:908: The following error occurred while executing this line:
17:07:03 deploy.xml:4: java.lang.OutOfMemoryError: PermGen space
正如您所看到的,条件已成功评估,因为消息我应该在这里失败!被打印。
stop_execution_on_fail 变量包含以逗号分隔的系统失败列表:
10:12:56 [echo] Error during deployment of system1:
10:12:56 [echo] The following error occurred while executing this line:
10:12:56 [echo] deploy.xml:739: The following error occurred while executing this line:
10:12:56 [echo] deploy.xml:647: The following error occurred while executing this line:
10:12:56 [echo] deploy.xml:473: The following error occurred while executing this line:
10:12:56 [echo] dbmaintain.xml:229: Unable to perform db maintain task.
--- omitted ---
10:12:56 [echo] I should fail here!
答案 0 :(得分:0)
我相信你的问题在你的
之内 <contains string="${stop_execution_on_fail}" substring="${system}" />
您正在检查整个字符串stop_execution_on_fail
中与系统匹配的子字符串。但是,你的尝试:
<trycatch property="error_system">
在error_system
属性中设置错误消息,您不在包含中检查。
尝试将<contains>
更改为:
<contains string="${error_system}" substring="${system}" />
答案 1 :(得分:0)
我使用Chad Nouis'建议跟踪了错误,并发现了以下内容:
parallel
目标<for>
调用中的deploy_all
属性设置为true。在这种情况下,即使将threadCount
设置为1,Ant也会使目标失败,但不会阻止for循环运行下一个循环(尽管我确信它应该)。谢谢你,Chad Nouis!