2015-12-15 63 views
2

我不得不在cd #{deploy_to}/currentraise_on_non_zero_exit: false的許多任務。真難聞。我怎樣才能縮短卡皮斯特拉諾的說法

是否有任何內置函數可以讓我縮短我的陳述?

工頭配置

namespace :foreman do 
    task :export do 
     on roles(:web) do |host| 
     execute %Q(cd #{deploy_to}/current && sudo foreman export upstart /etc/init -a #{ENV['APP_NAME']} -u #{ENV['DEPLOYER']} -l /var/#{ENV['APP_NAME']}/log) 
     end 
    end 
    task :start do 
     on roles(:web) do |host| 
     execute "cd #{deploy_to}/current && sudo start #{ENV['APP_NAME']} ", raise_on_non_zero_exit: false 
     end 
    end 
    task :stop do 
     on roles(:web) do |host| 
     execute "cd #{deploy_to}/current && sudo stop #{ENV['APP_NAME']} ", raise_on_non_zero_exit: false 
     end 
    end 
    end # foreman 

回答

1

您可以使用capistranos「內」幫手整理這一點,以及包裹在自己的helper方法加薪?

within current_path do 
    execute_without_fail "..." 
end 

def execute_without_fail cmd 
    execute cmd, raise_on_non_zero_exit: false 
end 
相關問題