Capistrano & Bash: ignore command exit status

前端 未结 7 680
礼貌的吻别
礼貌的吻别 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条回答
  •  Happy的楠姐
    2021-01-31 14:55

    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.

    # Processes the command in parallel on all specified hosts. If the command
    # fails (non-zero return code) on any of the hosts, this will raise a
    # Capistrano::CommandError.
    def process!
      loop do
        break unless process_iteration { @channels.any? { |ch| !ch[:closed] } }
      end
    
      logger.trace "command finished" if logger
    
      if (failed = @channels.select { |ch| ch[:status] != 0 }).any?
        commands = failed.inject({}) { |map, ch| (map[ch[:command]] ||= []) << ch[:server]; map }
        message = commands.map { |command, list| "#{command.inspect} on #{list.join(',')}" }.join("; ")
        error = CommandError.new("failed: #{message}")
        error.hosts = commands.values.flatten
        raise error
      end
    
      self
    end
    

提交回复
热议问题