Commit bdc10796 authored by Marius Bobin's avatar Marius Bobin Committed by Fabio Pitino

Check runner compatibility with allow_failure:exit_codes

Check runner compatibility with allow_failure:exit_codes
parent f8fd6d01
......@@ -27,7 +27,8 @@ module Ci
upload_multiple_artifacts: -> (build) { build.publishes_artifacts_reports? },
refspecs: -> (build) { build.merge_request_ref? },
artifacts_exclude: -> (build) { build.supports_artifacts_exclude? },
multi_build_steps: -> (build) { build.multi_build_steps? }
multi_build_steps: -> (build) { build.multi_build_steps? },
return_exit_code: -> (build) { build.exit_codes_defined? }
}.freeze
DEFAULT_RETRIES = {
......@@ -1038,6 +1039,10 @@ module Ci
end
end
def exit_codes_defined?
options.dig(:allow_failure_criteria, :exit_codes).present?
end
protected
def run_status_commit_hooks!
......
......@@ -4360,7 +4360,7 @@ RSpec.describe Ci::Build do
end
describe '#supported_runner?' do
let_it_be(:build) { create(:ci_build) }
let_it_be_with_refind(:build) { create(:ci_build) }
subject { build.supported_runner?(runner_features) }
......@@ -4425,6 +4425,41 @@ RSpec.describe Ci::Build do
it { is_expected.to be_falsey }
end
end
context 'when `return_exit_code` feature is required by build' do
let(:options) { { allow_failure_criteria: { exit_codes: [1] } } }
before do
build.update!(options: options)
end
context 'when runner provides given feature' do
let(:runner_features) { { return_exit_code: true } }
it { is_expected.to be_truthy }
end
context 'when runner does not provide given feature' do
let(:runner_features) { {} }
it { is_expected.to be_falsey }
end
context 'when the runner does not provide all of the required features' do
let(:options) do
{
allow_failure_criteria: { exit_codes: [1] },
artifacts: { reports: { junit: "junit.xml" } }
}
end
let(:runner_features) { { return_exit_code: true } }
it 'requires `upload_multiple_artifacts` too' do
is_expected.to be_falsey
end
end
end
end
describe '#deployment_status' do
......@@ -4927,4 +4962,56 @@ RSpec.describe Ci::Build do
end
end
end
describe '#exit_codes_defined?' do
let(:options) { {} }
before do
build.options.merge!(options)
end
subject(:exit_codes_defined) do
build.exit_codes_defined?
end
context 'without allow_failure_criteria' do
it { is_expected.to be_falsey }
end
context 'when exit_codes is nil' do
let(:options) do
{
allow_failure_criteria: {
exit_codes: nil
}
}
end
it { is_expected.to be_falsey }
end
context 'when exit_codes is an empty array' do
let(:options) do
{
allow_failure_criteria: {
exit_codes: []
}
}
end
it { is_expected.to be_falsey }
end
context 'when exit_codes are defined' do
let(:options) do
{
allow_failure_criteria: {
exit_codes: [5, 6]
}
}
end
it { is_expected.to be_truthy }
end
end
end
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