1

我想在 Capistrano 中设置这个延迟变量,这取决于我在调用任务期间设置的一些变量

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

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

如果运行任务会发生此错误

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)

这让我很生气。为什么 Capistrano 2.x 没有一种简单的方法来访问我调用的变量。

4

2 回答 2

1

看起来,fetch做你想做的

p "INSTALLATION_DIR >>> #{fetch(:installation_dir)}"
于 2013-11-05T11:10:18.697 回答
0

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'].

于 2013-07-03T11:57:52.347 回答