robkuz
robkuz

Reputation: 9904

Why cant I access a variable outside a Capistrano task

I have want to set this deferred variable in Capistrano which depends on some variable I set during calling the task

set(:installation_dir) do 
    if target == "staging"
        "/some/path"
    else
        "/some/other/path"
    end
end

task :foo do
    p "INSTALLATION_DIR >>> #{installation_dir}"
end

If running the task this error happens

Hector:monitoring-agent robertj$ cap foo -s target=development
/Users/robertj/.rvm/gems/ruby-2.0.0-p0@pf/gems/capistrano-2.15.4/lib/capistrano/configuration/variables.rb:122:in 
`method_missing_with_variables': undefined local variable or method `target' for 
#<Capistrano::Configuration:0x007fd6a22f9100> (NameError)

This is making me mad. Why doesnt Capistrano 2.x have a simple way to access variables where ever I call.

Upvotes: 1

Views: 932

Answers (2)

akorablev
akorablev

Reputation: 11

Looks like, fetch do what you want

p "INSTALLATION_DIR >>> #{fetch(:installation_dir)}"

Upvotes: 1

marko
marko

Reputation: 1217

When you run it like that, you're setting an environment variable. To use it in your Capistrano script you need to set :target, ENV['target'].

Upvotes: 0

Related Questions