Welcome to mirror list, hosted at ThFree Co, Russian Federation.

evaluate_workflow_rules.rb « chain « pipeline « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0ee9485eebc312478c57ad92f1a937af3a10038b (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
# frozen_string_literal: true

module Gitlab
  module Ci
    module Pipeline
      module Chain
        class EvaluateWorkflowRules < Chain::Base
          include ::Gitlab::Utils::StrongMemoize
          include Chain::Helpers

          def perform!
            return unless Feature.enabled?(:workflow_rules, @pipeline.project)

            unless workflow_passed?
              error('Pipeline filtered out by workflow rules.')
            end
          end

          def break?
            return false unless Feature.enabled?(:workflow_rules, @pipeline.project)

            !workflow_passed?
          end

          private

          def workflow_passed?
            strong_memoize(:workflow_passed) do
              workflow_rules.evaluate(@pipeline, global_context).pass?
            end
          end

          def workflow_rules
            Gitlab::Ci::Build::Rules.new(
              workflow_config[:rules], default_when: 'always')
          end

          def global_context
            Gitlab::Ci::Build::Context::Global.new(
              @pipeline, yaml_variables: workflow_config[:yaml_variables])
          end

          def workflow_config
            @command.config_processor.workflow_attributes || {}
          end
        end
      end
    end
  end
end