readonly
readonly

Reputation: 355804

How do you add some steps to a capistrano task?

I'd like to stop some processes before running the deploy:migrate task. I know that I can redefine the deploy:migrate task by copying the existing code and adding the stop/start steps at the beginning and end of the task.

I'm wondering if there is a way to avoid copying the code from the default deploy:migrate task in my version of the task. Is there a way to refer to the existing deploy:migrate task when defining a new task of the same name?

Upvotes: 12

Views: 4430

Answers (2)

user1102967
user1102967

Reputation:

For my requirements, I override the existing task in deploy.rb

namespace :deploy do
  # to Override deploy:migrate task
  task :precompile, :roles => :app, :except => { :no_release => true } do
    run "your modified commands"
  end
  # to override deploy:assets:precompile task
  namespace :assets do
    task :precompile, :roles => :app, :except => { :no_release => true } do
      run "your modified commands"
    end
  end
end

Upvotes: 0

Emily
Emily

Reputation: 18193

Rather than redefining deploy:migrate, you should define a before or after hook for it. First, create a new task that does the stuff you need to do:

task :custom_name do
  # whatever you need to do
end

And then set this new task to be run before or after the deploy:migrate task by doing one of the following:

before "deploy:migrate", :custom_name
after "deploy:migrate", :custom_name

Upvotes: 21

Related Questions