Commit b3b5c808 authored by Stan Hu's avatar Stan Hu

Coerce CI auto_retry max value to an integer

Users that used a string (e.g. `'3'` instead of 3) would encounter
an exception such as:

```
ArgumentError: comparison of String with 0 failed
```

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/233035
parent 9b94d4e7
...@@ -30,7 +30,7 @@ class Gitlab::Ci::Build::AutoRetry ...@@ -30,7 +30,7 @@ class Gitlab::Ci::Build::AutoRetry
end end
def options_retry_max def options_retry_max
options_retry[:max] if retry_on_reason_or_always? Integer(options_retry[:max], exception: false) if retry_on_reason_or_always?
end end
def options_retry_when def options_retry_when
......
...@@ -16,6 +16,7 @@ RSpec.describe Gitlab::Ci::Build::AutoRetry do ...@@ -16,6 +16,7 @@ RSpec.describe Gitlab::Ci::Build::AutoRetry do
"retries are disabled" | 0 | { max: 0 } | nil | false "retries are disabled" | 0 | { max: 0 } | nil | false
"max equals count" | 2 | { max: 2 } | nil | false "max equals count" | 2 | { max: 2 } | nil | false
"max is higher than count" | 1 | { max: 2 } | nil | true "max is higher than count" | 1 | { max: 2 } | nil | true
"max is a string" | 1 | { max: '2' } | nil | true
"matching failure reason" | 0 | { when: %w[api_failure], max: 2 } | :api_failure | true "matching failure reason" | 0 | { when: %w[api_failure], max: 2 } | :api_failure | true
"not matching with always" | 0 | { when: %w[always], max: 2 } | :api_failure | true "not matching with always" | 0 | { when: %w[always], max: 2 } | :api_failure | true
"not matching reason" | 0 | { when: %w[script_error], max: 2 } | :api_failure | false "not matching reason" | 0 | { when: %w[script_error], max: 2 } | :api_failure | false
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment