Search code examples
capistranocapistrano3

User input in capistrano 3.4


According to the documentation of capistrano, I can get user input with the ask() method. I created the following task:

desc "Ask for user input"
task :ask_for_user_input do
  ask ':update_assets', 'Update assets (y/n, default=n)?', 'n'
end

and in deploy.rb I have

namespace :deploy do
  ...
  before :deploy, "deploy:ask_for_user_input"
  ...
end

But no matter what, capistrano never asks for user input. I tried different variations (e.g. putting the "ask" method directly in deploy.rb or my stage files but it did not change anything. What am I missing here?


Solution

  • I prompt for user input in my staging file. Perhaps it's your syntax? The ask() method can be used like this:

    # ask for user input
    ask(:update_assets, 'Update assets (y/n, default=n)', 'n', echo: true)
    # get the user input
    fetch(:update_assets)
    

    Sources: Capistrano User Input, How can I get Capistrano to prompt for a password?