BigW Consortium Gitlab

global.rb 2.18 KB
Newer Older
1 2 3
module Gitlab
  module Ci
    class Config
4
      module Entry
5
        ##
6
        # This class represents a global entry - root Entry for entire
7 8
        # GitLab CI Configuration file.
        #
9
        class Global < Node
10 11
          include Configurable

12
          entry :before_script, Entry::Script,
13
            description: 'Script that will be executed before each job.'
14

15
          entry :image, Entry::Image,
16
            description: 'Docker image that will be used to execute jobs.'
17

18
          entry :services, Entry::Services,
19
            description: 'Docker images that will be linked to the container.'
20

21
          entry :after_script, Entry::Script,
22
            description: 'Script that will be executed after each job.'
23

24
          entry :variables, Entry::Variables,
25
            description: 'Environment variables that will be used.'
26

27
          entry :stages, Entry::Stages,
28 29
            description: 'Configuration of stages for this pipeline.'

30
          entry :types, Entry::Stages,
31
            description: 'Deprecated: stages for this pipeline.'
32

33
          entry :cache, Entry::Cache,
34 35 36
            description: 'Configure caching between build jobs.'

          helpers :before_script, :image, :services, :after_script,
37
                  :variables, :stages, :types, :cache, :jobs
38

39 40 41 42 43
          def compose!(_deps = nil)
            super(self) do
              compose_jobs!
              compose_deprecated_entries!
            end
44 45
          end

46 47
          private

48
          def compose_jobs!
49
            factory = Entry::Factory.new(Entry::Jobs)
50
              .value(@config.except(*self.class.nodes.keys))
51 52
              .with(key: :jobs, parent: self,
                    description: 'Jobs definition for this pipeline')
53

54 55
            @entries[:jobs] = factory.create!
          end
56

57
          def compose_deprecated_entries!
58 59 60 61
            ##
            # Deprecated `:types` key workaround - if types are defined and
            # stages are not defined we use types definition as stages.
            #
62 63 64
            if types_defined? && !stages_defined?
              @entries[:stages] = @entries[:types]
            end
65

66
            @entries.delete(:types)
67
          end
68 69 70 71 72
        end
      end
    end
  end
end