1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00
capistrano/docs/documentation/getting-started/before-after/index.markdown
Rogelio J. Samour 3a96e88367 Include :deploy namespace in block example
Small tweak to the documentation on before/after hooks.
2017-10-16 10:12:09 -07:00

57 lines
991 B
Markdown

---
title: Before / After Hooks
layout: default
---
Where calling on the same task name, executed in order of inclusion
```ruby
# 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
```
If it makes sense for your use case (often, that means *generating a file*)
the Rake prerequisite mechanism can be used:
```ruby
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
```
The final way to call out to other tasks is to simply `invoke()` them:
```ruby
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
```
This method is widely used.