Capistrano run local command exit on failure

橙三吉。 提交于 2019-12-23 21:31:08

问题


I would like to run local commands and exit on failure of any command. whats the best way to do this with capistrano? run_locally will continue going on failure.

Do i have to check the last commands exist status everytime (or create a custom run locally function)?


回答1:


I had to create my own function like this:

task :build_backend do
  run_local("echo hello")
  run_local("abcdef")
  run_local("echo 'not run'")
end

def run_local(cmd)
  system cmd
  if($?.exitstatus != 0) then
    puts 'exit code: ' + $?.exitstatus.to_s
    exit
  end
end

Using this




回答2:


Generally in shell you can run multiple commands the way you want by command1 --some-argument foo && command2 && command3. the && operator will cause, that the chain will stop when one command fails (returns non-zero return value).



来源:https://stackoverflow.com/questions/9625622/capistrano-run-local-command-exit-on-failure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!