Ant-contrib 应该会失败但不会
Ant-contrib should fail but doesn't
我正在尝试使用一个包含两个目标的脚本来部署多个系统。当一个系统部署失败时,我想停止整个脚本并失败。
<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>
问题是条件被正确评估并且消息 "I should fail here!" 被打印,但是构建没有失败并继续部署下一个系统。
变量 ${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
我相信你的问题在你的
<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}" />
我使用 Chad Nouis' 的建议追查了错误并发现了以下内容:
- 首先,当我没有 post 实际代码而只是摘录和替换一些变量时,我很愚蠢。真丢脸!
deploy_all
目标中 <for>
调用中的 parallel
属性设置为 true。在那种情况下,即使将 threadCount
设置为 1,Ant 也会使目标失败,但不会阻止 for 循环从 运行 下一个循环(尽管我相信它应该)。
谢谢,Chad Nouis!
我正在尝试使用一个包含两个目标的脚本来部署多个系统。当一个系统部署失败时,我想停止整个脚本并失败。
<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>
问题是条件被正确评估并且消息 "I should fail here!" 被打印,但是构建没有失败并继续部署下一个系统。
变量 ${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
我相信你的问题在你的
<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}" />
我使用 Chad Nouis' 的建议追查了错误并发现了以下内容:
- 首先,当我没有 post 实际代码而只是摘录和替换一些变量时,我很愚蠢。真丢脸!
deploy_all
目标中<for>
调用中的parallel
属性设置为 true。在那种情况下,即使将threadCount
设置为 1,Ant 也会使目标失败,但不会阻止 for 循环从 运行 下一个循环(尽管我相信它应该)。
谢谢,Chad Nouis!