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:

  • Opscode Chef - way to cleanup /shared/cached-copy
  • Chef Integration with Jenkins
  • Is there a way to use private git repository with Berkshelf
  • Installing a Ruby gem from a Github repository using Chef?
  • Jenkins CI with chef
  • Chef: How to add changes made via dashboard to 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!

  • Git pull, fatal: loose object
  • Teaching git while keeping it 'as easy as svn'
  • Using LibGit2Sharp to truncate GIT commit history
  • git pull subtree deletes everything
  • Auto commit on file modify with SVN (or git)?
  • Why should a business use distributed version control?
  • 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.