我的厨师食谱中有以下片段。
begin
execute 'run_tests' do
command comand_string_to_run_nUnint
user "user"
password passkey
end
ensure
execute 'upload_report' do
command uplaod
user "user"
password passkey
end
end
问题是在所有测试通过的情况下报告上传成功,但当任何测试用例失败时无法上传。
我如何确保在所有情况下都上传报告。
有没有不同的方法来处理异常?
ps:我正在上传到名为 Nexus 的工件存储库。
您可以将其ignore_failure true
用于您的execute[run_tests]
资源。这样,Chef 将继续运行配方,即使此命令以错误代码退出。
execute 'run_tests' do
ignore_failure true
command comand_string_to_run_nUnint
user "user"
password passkey
end
另一种可能性是将returns
属性用于execute[run_tests]
资源。当测试失败时,“comand_string_to_run_nUnint”以非零代码退出,您可以将此非零代码(例如 2)添加到returns
属性中。这样 Chef 会认为一切正常,并且仍然继续运行配方。
execute 'run_tests' do
returns [0, 2]
command comand_string_to_run_nUnint
user "user"
password passkey
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句