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_command
has an exit status != 0, then Capistrano considers it failed and exits. How can I make capistrano keep going when exit when the exit status is not 0? I've changed my_command
to my_command;echo
and it works but it feels like a hack.
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:
Normally, I think the first solution is just fine -- I'd make it document itself tho:
The simplest way is to just append true to the end of your command.
Becomes
I just redirect STDERR and STDOUT to /dev/null, so your
becomes
this works for standard unix tools pretty well, where, say, cp or ln could fail, but you don't want to halt deployment on such a failure.
I find the easiest option to do this:
Notice:
:
is the NOP command so the exit code will simply be ignored.You'll need to patch the Capistrano code if you want it to do different things with the exit codes; it's hard-coded to raise an exception if the exit status is not zero.
Here's the relevant portion of lib/capistrano/command.rb. The line that starts with
if (failed
... is the important one. Basically it says if there are any nonzero return values, raise an error.I not sure what version they added this code but I like handling this problem by using
raise_on_non_zero_exit
Here is where that feature is implemented in the gem. https://github.com/capistrano/sshkit/blob/4cfffffde6a643520986ed0f66f21d1357e0cd458b/lib/sshkit/command.rb#L94