How do I invoke one Capistrano task from another?

后端 未结 5 1622
走了就别回头了
走了就别回头了 2021-02-03 17:38

How do I invoke one Capistrano task from another?

For example:

task :foo do
  # stuff
end

task :bar do
  # INVOKE :foo
end
相关标签:
5条回答
  • 2021-02-03 18:14

    For the record: in the Capistrano 3, use invoke(), e.g.

    desc "Task that does something"
    task :do_something do
      invoke 'namespace:task'
    end
    

    More at https://github.com/capistrano/capistrano#before--after

    0 讨论(0)
  • 2021-02-03 18:20

    You can do it by using namespace:

    namespace :test do
      task :one do
      end
      task :two do
        test.one
        #or just directly call it:
        one
      end
    end
    

    Just be careful with the name you use to not overwrite some important function.

    0 讨论(0)
  • 2021-02-03 18:24

    If the task lives in another namespace, you can use find_and_execute_task instead.

    0 讨论(0)
  • 2021-02-03 18:27

    Generally you do this by defining dependencies:

    before :bar, :foo
    
    0 讨论(0)
  • 2021-02-03 18:27

    you also could use Rake::Task["namespace:task"].invoke, this works

    0 讨论(0)
提交回复
热议问题