Commit 95bad051 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'timeout-in-default' into 'master'

Adds timeout support in default CI/CD configuration

See merge request gitlab-org/gitlab!19847
parents f86b545f 1e7fe975
...@@ -135,6 +135,7 @@ The following job parameters can be defined inside a `default:` block: ...@@ -135,6 +135,7 @@ The following job parameters can be defined inside a `default:` block:
- [`before_script`](#before_script-and-after_script) - [`before_script`](#before_script-and-after_script)
- [`after_script`](#before_script-and-after_script) - [`after_script`](#before_script-and-after_script)
- [`cache`](#cache) - [`cache`](#cache)
- [`timeout`](#timeout)
- [`interruptible`](#interruptible) - [`interruptible`](#interruptible)
In the following example, the `ruby:2.5` image is set as the default for all In the following example, the `ruby:2.5` image is set as the default for all
......
...@@ -13,7 +13,7 @@ describe EE::Gitlab::Ci::Config::Entry::Bridge do ...@@ -13,7 +13,7 @@ describe EE::Gitlab::Ci::Config::Entry::Bridge do
# that we know that we don't want to inherit # that we know that we don't want to inherit
# as they do not have sense in context of Bridge # as they do not have sense in context of Bridge
let(:ignored_inheritable_columns) do let(:ignored_inheritable_columns) do
%i[before_script after_script image services cache interruptible] %i[before_script after_script image services cache interruptible timeout]
end end
end end
......
...@@ -14,7 +14,8 @@ module Gitlab ...@@ -14,7 +14,8 @@ module Gitlab
include ::Gitlab::Config::Entry::Inheritable include ::Gitlab::Config::Entry::Inheritable
ALLOWED_KEYS = %i[before_script image services ALLOWED_KEYS = %i[before_script image services
after_script cache interruptible].freeze after_script cache interruptible
timeout].freeze
validations do validations do
validates :config, allowed_keys: ALLOWED_KEYS validates :config, allowed_keys: ALLOWED_KEYS
...@@ -44,7 +45,11 @@ module Gitlab ...@@ -44,7 +45,11 @@ module Gitlab
description: 'Set jobs interruptible default value.', description: 'Set jobs interruptible default value.',
inherit: false inherit: false
helpers :before_script, :image, :services, :after_script, :cache, :interruptible entry :timeout, Entry::Timeout,
description: 'Set jobs default timeout.',
inherit: false
helpers :before_script, :image, :services, :after_script, :cache, :interruptible, :timeout
private private
......
...@@ -46,8 +46,6 @@ module Gitlab ...@@ -46,8 +46,6 @@ module Gitlab
message: "should be one of: #{ALLOWED_WHEN.join(', ')}" message: "should be one of: #{ALLOWED_WHEN.join(', ')}"
} }
validates :timeout, duration: { limit: ChronicDuration.output(Project::MAX_BUILD_TIMEOUT) }
validates :dependencies, array_of_strings: true validates :dependencies, array_of_strings: true
validates :extends, array_of_strings_or_string: true validates :extends, array_of_strings_or_string: true
validates :rules, array_of_hashes: true validates :rules, array_of_hashes: true
...@@ -103,6 +101,10 @@ module Gitlab ...@@ -103,6 +101,10 @@ module Gitlab
description: 'Set jobs interruptible value.', description: 'Set jobs interruptible value.',
inherit: true inherit: true
entry :timeout, Entry::Timeout,
description: 'Timeout duration of this job.',
inherit: true
entry :only, Entry::Policy, entry :only, Entry::Policy,
description: 'Refs policy this job will be executed for.', description: 'Refs policy this job will be executed for.',
default: Entry::Policy::DEFAULT_ONLY, default: Entry::Policy::DEFAULT_ONLY,
......
# frozen_string_literal: true
module Gitlab
module Ci
class Config
module Entry
##
# Entry that represents the interrutible value.
#
class Timeout < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
validations do
validates :config, duration: { limit: ChronicDuration.output(Project::MAX_BUILD_TIMEOUT) }
end
end
end
end
end
end
...@@ -26,7 +26,8 @@ describe Gitlab::Ci::Config::Entry::Default do ...@@ -26,7 +26,8 @@ describe Gitlab::Ci::Config::Entry::Default do
it 'contains the expected node names' do it 'contains the expected node names' do
expect(described_class.nodes.keys) expect(described_class.nodes.keys)
.to match_array(%i[before_script image services .to match_array(%i[before_script image services
after_script cache interruptible]) after_script cache interruptible
timeout])
end end
end end
end end
......
...@@ -24,7 +24,7 @@ describe Gitlab::Ci::Config::Entry::Job do ...@@ -24,7 +24,7 @@ describe Gitlab::Ci::Config::Entry::Job do
let(:result) do let(:result) do
%i[before_script script stage type after_script cache %i[before_script script stage type after_script cache
image services only except rules needs variables artifacts image services only except rules needs variables artifacts
environment coverage retry interruptible] environment coverage retry interruptible timeout]
end end
it { is_expected.to match_array result } it { is_expected.to match_array result }
...@@ -417,21 +417,21 @@ describe Gitlab::Ci::Config::Entry::Job do ...@@ -417,21 +417,21 @@ describe Gitlab::Ci::Config::Entry::Job do
context 'when timeout value is not correct' do context 'when timeout value is not correct' do
context 'when it is higher than instance wide timeout' do context 'when it is higher than instance wide timeout' do
let(:config) { { timeout: '3 months' } } let(:config) { { timeout: '3 months', script: 'test' } }
it 'returns error about value too high' do it 'returns error about value too high' do
expect(entry).not_to be_valid expect(entry).not_to be_valid
expect(entry.errors) expect(entry.errors)
.to include "job timeout should not exceed the limit" .to include "timeout config should not exceed the limit"
end end
end end
context 'when it is not a duration' do context 'when it is not a duration' do
let(:config) { { timeout: 100 } } let(:config) { { timeout: 100, script: 'test' } }
it 'returns error about wrong value' do it 'returns error about wrong value' do
expect(entry).not_to be_valid expect(entry).not_to be_valid
expect(entry.errors).to include 'job timeout should be a duration' expect(entry.errors).to include 'timeout config should be a duration'
end end
end end
end end
......
...@@ -1375,7 +1375,7 @@ module Gitlab ...@@ -1375,7 +1375,7 @@ module Gitlab
end end
it 'raises an error for invalid number' do it 'raises an error for invalid number' do
expect { builds }.to raise_error('jobs:deploy_to_production timeout should be a duration') expect { builds }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'jobs:deploy_to_production:timeout config should be a duration')
end 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