1

I have the below snippet in my 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"
        password passkey
     end
end

the problem is that the report is being uploaded successfully in case of all test passed, but fails to upload when there is a failure in any of the test case.

how do I ensure the report is uploaded in all cases.

is there a different way to handle exceptions?

ps: I am uploading to artifact repository named Nexus.

Stefan
  • 109,145
  • 14
  • 143
  • 218
zumblebox
  • 13
  • 5

1 Answers1

0

You can use ignore_failure true for your execute[run_tests] resource. This way Chef will continue to run the recipe, even if this command exits with error code.

execute 'run_tests' do
     ignore_failure true
     command comand_string_to_run_nUnint
     user "user"
     password passkey
 end

Another possibility is to use returns property for execute[run_tests] resource. When there are test failures the "comand_string_to_run_nUnint" exits with non-zero code, you can add this non-zero code (for example 2) to returns property. This way Chef will think that everything is ok and still continue to run the recipe.

execute 'run_tests' do
     returns [0, 2]
     command comand_string_to_run_nUnint
     user "user"
     password passkey
 end
Draco Ater
  • 20,820
  • 8
  • 62
  • 86