Last Updated: February 25, 2016
· danbt79

Prompt on Capistrano multistage deployments

Using development/staging/production deployments with Capistrano? Want to double-check that you really want to deploy to a particular environment?

Add this to your /config/deploy/[stage].rb

# Make sure we really want to target this environment!
puts "\e[0;35m =======================\e[0m\n"
puts "\e[0;35m Really deploy to PRODUCTION?\e[0m\n"
puts "\e[0;35m =======================\e[0m\n"

# Fetch user response
response = Capistrano::CLI.ui.ask "\e[0;32m [y]es or [n]o?\e[0m\n"

# Abort if required
unless response.to_s == 'y'
  puts "\e[0;31m Aborting......\e[0m\n"

Voila! You have pretty prompting to confirm what you're doing.

Want to see more? I've posted a quick overview on using multistage deployments to this gist: