Ruby 厨师长| |在异常情况下,救援模块不工作

Ruby 厨师长| |在异常情况下,救援模块不工作,ruby,nunit,chef-infra,nexus,chef-recipe,Ruby,Nunit,Chef Infra,Nexus,Chef Recipe,我的厨师食谱中有下面的片段 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" passw

我的厨师食谱中有下面的片段

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的工件存储库。

您可以使用
忽略\u failure true
作为
执行[运行测试]
资源。这样,Chef将继续运行配方,即使此命令退出时出现错误代码

execute 'run_tests' do
     ignore_failure true
     command comand_string_to_run_nUnint
     user "user"
     password passkey
 end
另一种可能是为
execute[run\u tests]
资源使用
returns
属性。当测试失败时,“comand_string_to_run_nunit”以非零代码退出,您可以将此非零代码(例如2)添加到
返回
属性。这样,厨师会认为一切都好,仍然继续运行食谱

execute 'run_tests' do
     returns [0, 2]
     command comand_string_to_run_nUnint
     user "user"
     password passkey
 end

您可以使用
ignore\u failure true
作为
execute[run\u tests]
资源。这样,Chef将继续运行配方,即使此命令退出时出现错误代码

execute 'run_tests' do
     ignore_failure true
     command comand_string_to_run_nUnint
     user "user"
     password passkey
 end
另一种可能是为
execute[run\u tests]
资源使用
returns
属性。当测试失败时,“comand_string_to_run_nunit”以非零代码退出,您可以将此非零代码(例如2)添加到
返回
属性。这样,厨师会认为一切都好,仍然继续运行食谱

execute 'run_tests' do
     returns [0, 2]
     command comand_string_to_run_nUnint
     user "user"
     password passkey
 end