default.rb 2.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
# frozen_string_literal: true

module Gitlab
  module Ci
    class Config
      module Entry
        ##
        # This class represents a default entry
        # Entry containing default values for all jobs
        # defined in configuration file.
        #
        class Default < ::Gitlab::Config::Entry::Node
          include ::Gitlab::Config::Entry::Configurable
14
          include ::Gitlab::Config::Entry::Inheritable
15
16

          ALLOWED_KEYS = %i[before_script image services
17
                            after_script cache interruptible
18
                            timeout retry tags].freeze
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

          validations do
            validates :config, allowed_keys: ALLOWED_KEYS
          end

          entry :before_script, Entry::Script,
            description: 'Script that will be executed before each job.',
            inherit: true

          entry :image, Entry::Image,
            description: 'Docker image that will be used to execute jobs.',
            inherit: true

          entry :services, Entry::Services,
            description: 'Docker images that will be linked to the container.',
            inherit: true

          entry :after_script, Entry::Script,
            description: 'Script that will be executed after each job.',
            inherit: true

          entry :cache, Entry::Cache,
            description: 'Configure caching between build jobs.',
            inherit: true

44
          entry :interruptible, ::Gitlab::Config::Entry::Boolean,
45
46
47
            description: 'Set jobs interruptible default value.',
            inherit: false

48
49
50
51
          entry :timeout, Entry::Timeout,
            description: 'Set jobs default timeout.',
            inherit: false

52
53
54
55
          entry :retry, Entry::Retry,
            description: 'Set retry default value.',
            inherit: false

56
57
58
59
60
61
          entry :tags, ::Gitlab::Config::Entry::ArrayOfStrings,
            description: 'Set the default tags.',
            inherit: false

          helpers :before_script, :image, :services, :after_script, :cache, :interruptible,
            :timeout, :retry, :tags
62
63
64

          private

65
66
          def overwrite_entry(deps, key, current_entry)
            inherited_entry = deps[key]
67

68
69
            if inherited_entry.specified? && current_entry.specified?
              raise InheritError, "#{key} is defined in top-level and `default:` entry"
70
            end
71
72

            inherited_entry unless current_entry.specified?
73
74
75
76
77
78
          end
        end
      end
    end
  end
end