I have a set of rake tasks where I need to invoke capistrano at some point. Edwin Goei's blog suggests shelling out to capistrano via "sh".
Is there a simpler way? It would seem you should be able to call the appropriate tasks programmatically. Thanks in advance.
Yes, Capistrano has programmatic access to the command-line components. If you want to call them from a rake task, though, you need to do a little extra work.
task :deploy
require 'rubygems'
require 'capistrano'
require 'capistrano/cli'
parameters = ["deploy"] # this is an array of the strings that come after
# cap on the command line. e.g.,
# ["deploy", "-S", "revision=1024"] gives you local var
# revision in your deploy.rb.
# The following is required ONLY when you run Capistrano 2+ from Rake,
# because Rake adds the methods from FileUtils to Object. FileUtils includes
# a method called symlink which interferes with Capistrano's symlink task.
Capistrano::Configuration::Namespaces::Namespace.class_eval { undef :symlink }
Capistrano::CLI.parse(parameters).execute!
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With