summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/config/entry/global.rb
blob: c85f68c0911e83409ee716ec1ad758508bb9766f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# frozen_string_literal: true

module Gitlab
  module Ci
    class Config
      module Entry
        ##
        # This class represents a global entry - root Entry for entire
        # GitLab CI Configuration file.
        #
        class Global < ::Gitlab::Config::Entry::Node
          include ::Gitlab::Config::Entry::Configurable

          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 :variables, Entry::Variables,
            description: 'Environment variables that will be used.',
            inherit: true

          entry :stages, Entry::Stages,
            description: 'Configuration of stages for this pipeline.',
            inherit: true

          entry :types, Entry::Stages,
            description: 'Configuration of stages for this pipeline.',
            inherit: true

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

          entry :only, Entry::Policy,
            description: 'Refs policy this job will be executed for.',
            default: Entry::Policy::DEFAULT_GLOBAL_ONLY

          entry :except, Entry::Policy,
            description: 'Refs policy this job will be executed for.'

          helpers :before_script, :image, :services, :after_script,
                  :variables, :stages, :types, :cache, :only, :except

          def compose!(deps = nil)
            super(self) do
              inherit!(deps)
              compose_deprecated_entries!
            end
          end

          private

          def inherit!(deps)
            return unless deps

            self.class.nodes.each do |key, factory|
              next unless factory.inheritable?

              root_entry = deps[key]
              global_entry = self[key]

              if root_entry.specified? && !global_entry.specified?
                @entries[key] = root_entry
              end
            end
          end

          def compose_deprecated_entries!
            ##
            # Deprecated `:types` key workaround - if types are defined and
            # stages are not defined we use types definition as stages.
            #
            if types_defined? && !stages_defined?
              @entries[:stages] = @entries[:types]
            end

            @entries.delete(:types)
          end
        end
      end
    end
  end
end