【发布时间】:2016-03-08 16:42:41
【问题描述】:
我正在尝试使用一个包含两个目标的脚本来部署多个系统。当一个系统部署失败时,我想停止整个脚本并失败。
<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>
问题是条件被正确评估并且消息“我应该在这里失败!”被打印,但构建没有失败并继续部署下一个系统。
变量 ${stop_execution_on_fail} 被提供给脚本并包含应该使整个构建失败(而不是部署其余系统)的系统列表。
有时,在部署多个内存不足的系统后构建会失败。
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
我正在运行 Jenkins 1.642.1、JDK 1.8.0_74 和 Ant 1.9.2。
有什么想法吗?
编辑(基于 pczeus 的评论):打印以下内容(不要介意时间戳,我从另一个版本中获取):
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!
如您所见,条件评估成功,因为消息 I should fail here! 被打印出来。
stop_execution_on_fail 变量包含以逗号分隔的失败系统列表:
system1,system2,system3
【问题讨论】:
-
修复 PermGen 空间问题:stackoverflow.com/questions/6387380/…
-
@BrunoLavit 谢谢,当我测试使用 JDK6 运行脚本时,我把它留在了错误消息中。 JDK8 不打印任何东西,它只是被卡住了。
-
尝试使用
-logger org.apache.tools.ant.listener.ProfileLogger选项运行Ant。这将显示 Ant 是否在<echo>任务之后进入了<fail>任务。还可以考虑使用-debug选项运行 Ant,看看它是否揭示了任何问题。 -
谢谢,对我帮助很大!我不知道 ˛
-logger开关。
标签: jenkins ant ant-contrib