7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/buildkite/pipelines/helpers/retry.rb', line 7
def automatic_retry_on(exit_status: nil, limit: nil, signal_reason: nil)
raise 'limit must set for `automatic_retry_on`.' unless limit
if exit_status.nil? && signal_reason.nil?
raise 'signal_reason or exit_status must set for `automatic_retry_on`.'
end
retry_value = get(:retry) || set(:retry, {})
unless retry_value[:automatic].is_a?(Array)
retry_value[:automatic] = []
end
automatic_options = { limit: limit }
if exit_status && signal_reason
retry_value[:automatic].delete_if do |rule|
rule[:exit_status] == exit_status && rule[:signal_reason] == signal_reason
end
automatic_options[:exit_status] = exit_status
automatic_options[:signal_reason] = signal_reason
elsif exit_status
retry_value[:automatic].delete_if { |rule| rule[:exit_status] == exit_status }
automatic_options[:exit_status] = exit_status
elsif signal_reason
retry_value[:automatic].delete_if { |rule| rule[:signal_reason] == signal_reason }
automatic_options[:signal_reason] = signal_reason
end
retry_value[:automatic].push(automatic_options)
end
|