Class: Gitlab::Ci::ProjectConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/project_config.rb,
lib/gitlab/ci/project_config/bridge.rb,
lib/gitlab/ci/project_config/source.rb,
lib/gitlab/ci/project_config/parameter.rb,
lib/gitlab/ci/project_config/compliance.rb,
lib/gitlab/ci/project_config/auto_devops.rb,
lib/gitlab/ci/project_config/project_setting.rb,
lib/gitlab/ci/project_config/security_policy_default.rb

Overview

Locates project CI config

Defined Under Namespace

Classes: AutoDevops, Bridge, Compliance, Parameter, ProjectSetting, SecurityPolicyDefault, Source

Constant Summary collapse

STANDARD_SOURCES =

The order of sources is important:

  • EE uses Compliance first since it must be used first if compliance templates are enabled.

  • Parameter is used by on-demand security scanning which passes the actual CI YAML to use as argument.

  • Bridge is used for downstream pipelines since the config is defined in the bridge job. If lower in priority, it would evaluate the project’s YAML file instead.

  • ProjectSetting takes care of CI config coming defined in a project. This can be the project itself, remote or external.

  • AutoDevops is used as default option if nothing else is found and if AutoDevops is enabled.

  • EE uses SecurityPolicyDefault and it should come last. It is only necessary if no other source is available. Based on the policy configuration different source can be used.

[
  ProjectConfig::Compliance,
  ProjectConfig::Parameter,
  ProjectConfig::Bridge,
  ProjectConfig::ProjectSetting,
  ProjectConfig::AutoDevops
].freeze
FALLBACK_POLICY_SOURCE =
ProjectConfig::SecurityPolicyDefault

Instance Method Summary collapse

Constructor Details

#initialize(project:, sha:, custom_content: nil, pipeline_source: nil, pipeline_source_bridge: nil, triggered_for_branch: nil, ref: nil, source_branch: nil, pipeline_policy_context: nil, inputs: nil) ⇒ ProjectConfig

rubocop:disable Metrics/ParameterLists – we need all these parameters



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gitlab/ci/project_config.rb', line 27

def initialize( # rubocop:disable Metrics/ParameterLists -- we need all these parameters
  project:, sha:, custom_content: nil, pipeline_source: nil, pipeline_source_bridge: nil,
  triggered_for_branch: nil, ref: nil, source_branch: nil, pipeline_policy_context: nil, inputs: nil)

  unless pipeline_policy_context&.pipeline_execution_context&.applying_config_override?
    @config = find_source(project: project,
      sha: sha,
      custom_content: custom_content,
      pipeline_source: pipeline_source,
      pipeline_source_bridge: pipeline_source_bridge,
      triggered_for_branch: triggered_for_branch,
      ref: ref,
      inputs: inputs
    )

    return if @config
  end

  fallback_config = FALLBACK_POLICY_SOURCE.new(
    project: project,
    pipeline_source: pipeline_source,
    triggered_for_branch: triggered_for_branch,
    source_branch: source_branch,
    pipeline_policy_context: pipeline_policy_context
  )

  @config = fallback_config if fallback_config.exists?
end

Instance Method Details

#exists?Boolean

Returns:



59
60
61
# File 'lib/gitlab/ci/project_config.rb', line 59

def exists?
  !!@config&.exists?
end

#external?Boolean

Returns:



63
64
65
# File 'lib/gitlab/ci/project_config.rb', line 63

def external?
  [:external_project_source, :remote_source].include?(source)
end