Skip to content

Commit

Permalink
Merge pull request #124 from casperisfine/retry-255
Browse files Browse the repository at this point in the history
Automatically retry on exit code 255
  • Loading branch information
byroot authored Oct 30, 2024
2 parents 1b53312 + 40c576b commit 1b7ea7d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lib/buildkite/config/build_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ def artifact_paths
end

def automatic_retry_on
{ exit_status: -1, limit: 2 }
[
{ exit_status: -1, limit: 2 },
{ exit_status: 255, limit: 2 },
]
end

def timeout_in_minutes
Expand Down
10 changes: 6 additions & 4 deletions lib/buildkite/config/rake_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ def rake(dir, task: "test", label: nil, service: "default", pre_steps: nil, env:

artifact_paths build_context.artifact_paths

if retry_on
automatic_retry_on(**retry_on)
else
automatic_retry_on(**build_context.automatic_retry_on)
if retry_on ||= build_context.automatic_retry_on
retry_on = [retry_on] unless retry_on.is_a?(Array)

retry_on.each do |retry_rule|
automatic_retry_on(**retry_rule)
end
end

timeout_in_minutes build_context.timeout_in_minutes
Expand Down
2 changes: 1 addition & 1 deletion test/buildkite_config/test_build_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def test_artifact_paths

def test_automatic_retry_on
sub = create_build_context
assert_equal({ exit_status: -1, limit: 2 }, sub.automatic_retry_on)
assert_equal([{ exit_status: -1, limit: 2 }, { exit_status: 255, limit: 2 }], sub.automatic_retry_on)
end

def test_timeout_in_minutes
Expand Down
2 changes: 1 addition & 1 deletion test/buildkite_config/test_rake_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_retry
end

assert_includes pipeline.to_h["steps"][0], "retry"
assert_equal({ "automatic" => [{ "limit" => 2, "exit_status" => -1 }] }, pipeline.to_h["steps"][0]["retry"])
assert_equal({ "automatic" => [{ "limit" => 2, "exit_status" => -1 }, { "limit" => 2, "exit_status" => 255 }] }, pipeline.to_h["steps"][0]["retry"])
end

def test_env
Expand Down

0 comments on commit 1b7ea7d

Please sign in to comment.