Reputation: 55
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:
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!
Upvotes: 5
Views: 1936
Reputation: 21206
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
Upvotes: 5