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:
- [`before_script`](#before_script-and-after_script)
- [`after_script`](#before_script-and-after_script)
- [`cache`](#cache)
- [`timeout`](#timeout)
- [`interruptible`](#interruptible)
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
# that we know that we don't want to inherit
# as they do not have sense in context of Bridge
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
......
......@@ -14,7 +14,8 @@ module Gitlab
include ::Gitlab::Config::Entry::Inheritable
ALLOWED_KEYS = %i[before_script image services
after_script cache interruptible].freeze
after_script cache interruptible
timeout].freeze
validations do
validates :config, allowed_keys: ALLOWED_KEYS
......@@ -44,7 +45,11 @@ module Gitlab
description: 'Set jobs interruptible default value.',
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
......
......@@ -46,8 +46,6 @@ module Gitlab
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 :extends, array_of_strings_or_string: true
validates :rules, array_of_hashes: true
......@@ -103,6 +101,10 @@ module Gitlab
description: 'Set jobs interruptible value.',
inherit: true
entry :timeout, Entry::Timeout,
description: 'Timeout duration of this job.',
inherit: true
entry :only, Entry::Policy,
description: 'Refs policy this job will be executed for.',
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
it 'contains the expected node names' do
expect(described_class.nodes.keys)
.to match_array(%i[before_script image services
after_script cache interruptible])
after_script cache interruptible
timeout])
end
end
end
......
......@@ -24,7 +24,7 @@ describe Gitlab::Ci::Config::Entry::Job do
let(:result) do
%i[before_script script stage type after_script cache
image services only except rules needs variables artifacts
environment coverage retry interruptible]
environment coverage retry interruptible timeout]
end
it { is_expected.to match_array result }
......@@ -417,21 +417,21 @@ describe Gitlab::Ci::Config::Entry::Job do
context 'when timeout value is not correct' 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
expect(entry).not_to be_valid
expect(entry.errors)
.to include "job timeout should not exceed the limit"
.to include "timeout config should not exceed the limit"
end
end
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
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
......
......@@ -1375,7 +1375,7 @@ module Gitlab
end
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
......
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