Dynamically skip Capistrano hooks

Updated . Posted . Visible to the public.

When you have a hook in your Capistrano file that dumps your remote database, you might not want it to dump each time you deploy (say, you're experimenting with staging and don't want ten dumps an hour). How to skip dump creation:

Capistrano 2

In your Capistrano file:

before 'deploy:update_code', 'db:dump' unless fetch(:skip_dump, false)

The second parameter of fetch sets a default value if skip_dump is not defined.

In your terminal:

cap staging deploy -S skip_dump=true

The -S must be a capital letter to set skip_dump before loading the recipes.

Capistrano 3

In your Capistrano file:

before 'deploy:updating', 'db:dump' unless ENV['SKIP_DUMP']

In your terminal:

SKIP_DUMP=true cap staging deploy
Dominik Schöler
Last edit
Niklas Hasselmeyer
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2011-06-10 12:19)