Question

I am using Chef to launch new environments that are controlled by GIT repositories. In my recipe, I have some code like:

begin
    git "#{current_release}/#{repo[:path]}" do
        repository repo[:repository]
        revision repo[:branch]
        action :sync
    end
rescue nil
end

This works well when the repository has content, but when it is empty - I get a Chef Exception:

Chef::Exceptions::UnresolvableGitReference: Unable to parse SHA reference for 'master' in repository

I understand that I can commit some sort of file into the repo to avoid this trouble, but this solution has it's own complications. Can anyone help with making this code "silently fail" when there is an exception like so? Essentially, if the git clone does not work, it's no big deal for my application.

Any tips are greatly appreciated! Using Chef 11 on AWS OpsWorks

Was it helpful?

Solution

Set ignore_failure true. This is a common attribute for all resources.

git "#{current_release}/#{repo[:path]}" do
    repository repo[:repository]
    revision repo[:branch]
    action :sync
    ignore_failure true
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top