Chef passing revision variable to deploy resource

I’m trying to pass the git branch that I want to deploy to the Chef deploy resource but it isn’t working, I’m guessing it’s because the resources are compiled separately and then just executed? But I might be wrong as my understanding of Ruby is limited.

So I’m trying to do this:

  • Chef Integration with Jenkins
  • use ssh keys with passphrase on a vagrant+chef setup
  • Resolve recursive git cookbook dependencies with Berkshelf
  • Is there a way to use private git repository with Berkshelf
  • Check out a Git repository with chef?
  • Chef will not checkout development branch from git
  • ruby_block 'revision' do
      block do
        # Some code determines the branch to be deployed
        branch = 'master'
    
        node.run_state['branch'] = branch
    
      end
    end
    
    deploy "#{node['path']['web']}" do
      action :deploy
      repository "#{node['git']['repository']}"
      revision "#{node.run_state['branch']}"
    end
    

    However the deploy resource doesn’t get passed that variable.

    Is this the correct way to go about this? Is there a better or other way?

    Thanks in advance!

  • How to list the change history of the directory tree in git
  • Git LFS skipped files
  • git fetch insufficient permission for adding an object to repository database .git/objects?
  • Complex setup for GIT: fork from Github to Bitbucket, PUSH to Bitbucket only
  • Create git branch, and revert original to upstream state
  • Is there a difference between git reset --hard HEAD and git checkout .?
  • One Solution collect form web for “Chef passing revision variable to deploy resource”

    At the moment chef compiles your deploy resource ruby_block resource is not run yet, so node.run_state[‘branch’] is not set. You have to move your deploy resource into ruby_block and define it dynamically.

    ruby_block 'revision' do
      block do
        # Some code determines the branch to be deployed
        branch = 'master'
    
        node.run_state['branch'] = branch
    
        depl = Chef::Resource::Deploy.new node['path']['web'], run_context
        depl.repository node['git']['repository']
        depl.revision node.run_state['branch']
        depl.run_action :deploy
      end
    end
    
    Git Baby is a git and github fan, let's start git clone.