部署前后钩子

在调用相同任务名称时,按包含顺序执行

# call an existing task
before :starting, :ensure_user

after :finishing, :notify


# or define in block
namespace :deploy do
  before :starting, :ensure_user do
    #
  end

  after :finishing, :notify do
    #
  end
end

如果您的用例有意义(通常,这意味着*生成文件*),可以使用 Rake 先决条件机制

desc "Create Important File"
file 'important.txt' do |t|
  sh "touch #{t.name}"
end
desc "Upload Important File"
task :upload => 'important.txt' do |t|
  on roles(:all) do
    upload!(t.prerequisites.first, '/tmp')
  end
end

调用其他任务的最后一种方法是简单地invoke()它们

namespace :example do
  task :one do
    on roles(:all) { info "One" }
  end
  task :two do
    invoke "example:one"
    on roles(:all) { info "Two" }
  end
end

此方法被广泛使用。

Fork me on GitHub