我的问题类似于How do I invoke one Capistrano task from another?
我想要的额外功能是能够在从foo调用参数时将参数传递到bar:
task :foo do
# this calls bar, I would like to pass params (i.e n = 10)
# as if I were calling cap bar -s n=10
# bar does not take arguments
bar
end
task :bar do
if exists?(:n)
puts "n is: #{n}"
end
end
答案 0 :(得分:2)
在capistrano 3.x
desc "I accept a parameter"
task :foo, :foo_param do |t, args|
foo_param = args[:foo_param]
puts "I am #{foo_param}"
end
desc "I call the foo task"
task :bar do
invoke("foo", "batman")
# prints "I am batman"
end
答案 1 :(得分:0)
Capistrano任务无法真正参数化。您可以定义辅助方法,如下所示:
task :foo do
bar(10)
end
def bar(n=variables[:n])
puts "N is #{n}"
end
如果你已经死定了:bar也是一个任务,试试这个技巧:
task :foo do
bar(10)
end
task :bar { bar }
def bar(n=variables[:n])
puts "N is #{n}"
end
请注意,任务必须在方法之前声明。