Module: Gitlab::Ci::Config::Entry::Processable

Extended by:
ActiveSupport::Concern
Includes:
Gitlab::Config::Entry::Attributable, Gitlab::Config::Entry::Configurable, Gitlab::Config::Entry::Inheritable
Included in:
Bridge, Job
Defined in:
lib/gitlab/ci/config/entry/processable.rb

Overview

Entry that represents a CI/CD Processable (a job)

Constant Summary collapse

PROCESSABLE_ALLOWED_KEYS =
%i[extends stage only except rules variables
inherit allow_failure when needs resource_group].freeze
MAX_NESTING_LEVEL =
10

Constants included from Gitlab::Config::Entry::Inheritable

Gitlab::Config::Entry::Inheritable::InheritError

Instance Method Summary collapse

Methods included from Gitlab::Config::Entry::Configurable

#entry_create!, #skip_config_hash_validation?

Instance Method Details

#compose!(deps = nil) ⇒ Object


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/gitlab/ci/config/entry/processable.rb', line 73

def compose!(deps = nil)
  super do
    has_workflow_rules = deps&.workflow_entry&.has_rules?

    # If workflow:rules: or rules: are used
    # they are considered not compatible
    # with `only/except` defaults
    #
    # Context: https://gitlab.com/gitlab-org/gitlab/merge_requests/21742
    if has_rules? || has_workflow_rules
      # Remove only/except defaults
      # defaults are not considered as defined
      @entries.delete(:only) unless only_defined? # rubocop:disable Gitlab/ModuleWithInstanceVariables
      @entries.delete(:except) unless except_defined? # rubocop:disable Gitlab/ModuleWithInstanceVariables
    end

    unless has_workflow_rules
      validate_against_warnings
    end

    yield if block_given?
  end
end

#manual_action?Boolean

Returns:

  • (Boolean)

136
137
138
# File 'lib/gitlab/ci/config/entry/processable.rb', line 136

def manual_action?
  self.when == 'manual'
end

#nameObject


109
110
111
# File 'lib/gitlab/ci/config/entry/processable.rb', line 109

def name
  [:name]
end

#overwrite_entry(deps, key, current_entry) ⇒ Object


113
114
115
116
117
118
# File 'lib/gitlab/ci/config/entry/processable.rb', line 113

def overwrite_entry(deps, key, current_entry)
  return unless inherit_entry&.default_entry&.inherit?(key)
  return unless deps.default_entry

  deps.default_entry[key] unless current_entry.specified?
end

#root_variables_inheritanceObject


132
133
134
# File 'lib/gitlab/ci/config/entry/processable.rb', line 132

def root_variables_inheritance
  inherit_entry&.variables_entry&.value
end

#validate_against_warningsObject


97
98
99
100
101
102
103
104
105
106
107
# File 'lib/gitlab/ci/config/entry/processable.rb', line 97

def validate_against_warnings
  # If rules are valid format and workflow rules are not specified
  return unless rules_value

  last_rule = rules_value.last

  if last_rule&.keys == [:when] && last_rule[:when] != 'never'
    docs_url = 'read more: https://docs.gitlab.com/ee/ci/troubleshooting.html#pipeline-warnings'
    add_warning("may allow multiple pipelines to run for a single action due to `rules:when` clause with no `workflow:rules` - #{docs_url}")
  end
end

#valueObject


120
121
122
123
124
125
126
127
128
129
130
# File 'lib/gitlab/ci/config/entry/processable.rb', line 120

def value
  { name: name,
    stage: stage_value,
    extends: extends,
    rules: rules_value,
    job_variables: variables_value.to_h,
    root_variables_inheritance: root_variables_inheritance,
    only: only_value,
    except: except_value,
    resource_group: resource_group }.compact
end