BigW Consortium Gitlab

global.rb 2.3 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
            description: 'Configure caching between build jobs.'

36 37 38
          entry :coverage, Entry::Coverage,
               description: 'Coverage configuration for this pipeline.'

39
          helpers :before_script, :image, :services, :after_script,
40
                  :variables, :stages, :types, :cache, :coverage, :jobs
41

42 43 44 45 46
          def compose!(_deps = nil)
            super(self) do
              compose_jobs!
              compose_deprecated_entries!
            end
47 48
          end

49 50
          private

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

57 58
            @entries[:jobs] = factory.create!
          end
59

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

69
            @entries.delete(:types)
70
          end
71 72 73 74 75
        end
      end
    end
  end
end