Capistrano & Bash: ignore command exit status

前端 未结 7 580
礼貌的吻别
礼貌的吻别 2021-01-31 14:11

I\'m using Capistrano run a remote task. My task looks like this:

task :my_task do
  run \"my_command\"
end

My problem is that if my_comm

7条回答
  •  北海茫月
    2021-01-31 14:53

    The +grep+ command exits non-zero based on what it finds. In the use case where you care about the output but don't mind if it's empty, you'll discard the exit state silently:

    run %Q{bash -c 'grep #{escaped_grep_command_args} ; true' }
    

    Normally, I think the first solution is just fine -- I'd make it document itself tho:

    cmd = "my_command with_args escaped_correctly"
    run %Q{bash -c '#{cmd} || echo "Failed: [#{cmd}] -- ignoring."'}
    

提交回复
热议问题