有没有更好的方法可以从耙中运行capistrano任务? [英] Is there a better way to run a capistrano task from within rake?

查看:80
本文介绍了有没有更好的方法可以从耙中运行capistrano任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组瑞克任务,需要在某些时候调用capistrano。 Edwin Goei的博客建议通过 sh轰炸Capistrano。

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.

推荐答案

是的,Capistrano可以通过编程方式访问命令行组件。但是,如果要从rake任务中调用它们,则需要做一些额外的工作。

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

这篇关于有没有更好的方法可以从耙中运行capistrano任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆