job.rb 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9
module Gitlab
  module Ci
    class Config
      module Node
        ##
        # Entry that represents a concrete CI/CD job.
        #
        class Job < Entry
          include Configurable
10

11 12 13 14
          validations do
            validates :config, presence: true
          end

15 16 17
          node :before_script, Script,
            description: 'Global before script overridden in this job.'

18 19 20 21 22 23
          node :stage, Stage,
            description: 'Pipeline stage this job will be executed into.'

          node :type, Stage,
            description: 'Deprecated: stage this job will be executed into.'

24
          helpers :before_script, :stage, :type
25 26

          def value
27 28 29 30 31 32 33
            raise InvalidError unless valid?

            ##
            # TODO, refactoring step: do not expose internal configuration,
            # return only hash value without merging it to internal config.
            #
            @config.merge(to_hash.compact)
34 35 36 37
          end

          private

38 39 40 41 42
          def to_hash
            { before_script: before_script,
              stage: stage }
          end

43 44 45 46 47 48 49 50 51
          def compose!
            super

            if type_defined? && !stage_defined?
              @entries[:stage] = @entries[:type]
            end

            @entries.delete(:type)
          end
52 53 54 55 56
        end
      end
    end
  end
end