Class: Gitlab::Ci::Config

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/config.rb,
lib/gitlab/ci/config/yaml.rb,
lib/gitlab/ci/config/entry/job.rb,
lib/gitlab/ci/config/entry/key.rb,
lib/gitlab/ci/config/yaml/tags.rb,
lib/gitlab/ci/config/entry/jobs.rb,
lib/gitlab/ci/config/entry/need.rb,
lib/gitlab/ci/config/entry/port.rb,
lib/gitlab/ci/config/entry/root.rb,
lib/gitlab/ci/config/entry/tags.rb,
lib/gitlab/ci/config/extendable.rb,
lib/gitlab/ci/config/normalizer.rb,
lib/gitlab/ci/config/entry/cache.rb,
lib/gitlab/ci/config/entry/files.rb,
lib/gitlab/ci/config/entry/image.rb,
lib/gitlab/ci/config/entry/needs.rb,
lib/gitlab/ci/config/entry/paths.rb,
lib/gitlab/ci/config/entry/ports.rb,
lib/gitlab/ci/config/entry/retry.rb,
lib/gitlab/ci/config/entry/rules.rb,
lib/gitlab/ci/config/entry/stage.rb,
lib/gitlab/ci/config/entry/bridge.rb,
lib/gitlab/ci/config/entry/caches.rb,
lib/gitlab/ci/config/entry/hidden.rb,
lib/gitlab/ci/config/entry/policy.rb,
lib/gitlab/ci/config/entry/prefix.rb,
lib/gitlab/ci/config/entry/stages.rb,
lib/gitlab/ci/config/entry/default.rb,
lib/gitlab/ci/config/entry/include.rb,
lib/gitlab/ci/config/entry/inherit.rb,
lib/gitlab/ci/config/entry/release.rb,
lib/gitlab/ci/config/entry/reports.rb,
lib/gitlab/ci/config/entry/service.rb,
lib/gitlab/ci/config/entry/timeout.rb,
lib/gitlab/ci/config/entry/trigger.rb,
lib/gitlab/ci/config/entry/commands.rb,
lib/gitlab/ci/config/entry/coverage.rb,
lib/gitlab/ci/config/entry/includes.rb,
lib/gitlab/ci/config/entry/services.rb,
lib/gitlab/ci/config/entry/workflow.rb,
lib/gitlab/ci/config/external/rules.rb,
lib/gitlab/ci/config/yaml/tags/base.rb,
lib/gitlab/ci/config/entry/artifacts.rb,
lib/gitlab/ci/config/entry/variables.rb,
lib/gitlab/ci/config/external/mapper.rb,
lib/gitlab/ci/config/entry/kubernetes.rb,
lib/gitlab/ci/config/entry/rules/rule.rb,
lib/gitlab/ci/config/extendable/entry.rb,
lib/gitlab/ci/config/external/context.rb,
lib/gitlab/ci/config/entry/environment.rb,
lib/gitlab/ci/config/entry/processable.rb,
lib/gitlab/ci/config/external/file/base.rb,
lib/gitlab/ci/config/external/processor.rb,
lib/gitlab/ci/config/normalizer/factory.rb,
lib/gitlab/ci/config/yaml/tags/resolver.rb,
lib/gitlab/ci/config/entry/allow_failure.rb,
lib/gitlab/ci/config/entry/include/rules.rb,
lib/gitlab/ci/config/external/file/local.rb,
lib/gitlab/ci/config/yaml/tags/reference.rb,
lib/gitlab/ci/config/edge_stages_injector.rb,
lib/gitlab/ci/config/entry/product/matrix.rb,
lib/gitlab/ci/config/entry/release/assets.rb,
lib/gitlab/ci/config/external/file/remote.rb,
lib/gitlab/ci/config/entry/inherit/default.rb,
lib/gitlab/ci/config/entry/trigger/forward.rb,
lib/gitlab/ci/config/external/file/project.rb,
lib/gitlab/ci/config/entry/product/parallel.rb,
lib/gitlab/ci/config/external/file/artifact.rb,
lib/gitlab/ci/config/external/file/template.rb,
lib/gitlab/ci/config/entry/inherit/variables.rb,
lib/gitlab/ci/config/entry/product/variables.rb,
lib/gitlab/ci/config/entry/include/rules/rule.rb,
lib/gitlab/ci/config/entry/release/assets/link.rb,
lib/gitlab/ci/config/entry/release/assets/links.rb,
lib/gitlab/ci/config/normalizer/matrix_strategy.rb,
lib/gitlab/ci/config/normalizer/number_strategy.rb,
lib/gitlab/ci/config/entry/reports/coverage_report.rb

Overview

Base GitLab CI Configuration facade

Defined Under Namespace

Modules: Entry, External, Yaml Classes: EdgeStagesInjector, Extendable, Normalizer

Constant Summary collapse

ConfigError =
Class.new(StandardError)
TIMEOUT_SECONDS =
30.seconds
TIMEOUT_MESSAGE =
'Resolving config took longer than expected'
RESCUE_ERRORS =
[
  Gitlab::Config::Loader::FormatError,
  Extendable::ExtensionError,
  External::Processor::IncludeError,
  Config::Yaml::Tags::TagError
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(config, project: nil, pipeline: nil, sha: nil, user: nil, parent_pipeline: nil, source: nil, logger: nil) ⇒ Config

Returns a new instance of Config.


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
# File 'lib/gitlab/ci/config.rb', line 24

def initialize(config, project: nil, pipeline: nil, sha: nil, user: nil, parent_pipeline: nil, source: nil, logger: nil)
  @logger = logger || ::Gitlab::Ci::Pipeline::Logger.new(project: project)
  @source_ref_path = pipeline&.source_ref_path
  @project = project

  if use_config_variables?
    pipeline ||= ::Ci::Pipeline.new(project: project, sha: sha, user: user, source: source)
  end

  @context = self.logger.instrument(:config_build_context) do
    build_context(project: project, pipeline: pipeline, sha: sha, user: user, parent_pipeline: parent_pipeline)
  end

  @context.set_deadline(TIMEOUT_SECONDS)

  @source = source

  @config = self.logger.instrument(:config_expand) do
    expand_config(config)
  end

  @root = self.logger.instrument(:config_compose) do
    Entry::Root.new(@config, project: project, user: user).tap(&:compose!)
  end
rescue *rescue_errors => e
  raise Config::ConfigError, e.message
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.


22
23
24
# File 'lib/gitlab/ci/config.rb', line 22

def context
  @context
end

#loggerObject (readonly)

Returns the value of attribute logger.


22
23
24
# File 'lib/gitlab/ci/config.rb', line 22

def logger
  @logger
end

#rootObject (readonly)

Returns the value of attribute root.


22
23
24
# File 'lib/gitlab/ci/config.rb', line 22

def root
  @root
end

#sourceObject (readonly)

Returns the value of attribute source.


22
23
24
# File 'lib/gitlab/ci/config.rb', line 22

def source
  @source
end

#source_ref_pathObject (readonly)

Returns the value of attribute source_ref_path.


22
23
24
# File 'lib/gitlab/ci/config.rb', line 22

def source_ref_path
  @source_ref_path
end

Instance Method Details

#errorsObject


56
57
58
# File 'lib/gitlab/ci/config.rb', line 56

def errors
  @root.errors
end

#included_templatesObject


91
92
93
# File 'lib/gitlab/ci/config.rb', line 91

def included_templates
  @context.includes.filter_map { |i| i[:location] if i[:type] == :template }
end

#jobsObject


83
84
85
# File 'lib/gitlab/ci/config.rb', line 83

def jobs
  root.jobs_value
end

#metadataObject


95
96
97
98
99
100
# File 'lib/gitlab/ci/config.rb', line 95

def 
  {
    includes: @context.includes,
    merged_yaml: @config&.deep_stringify_keys&.to_yaml
  }
end

#normalized_jobsObject


87
88
89
# File 'lib/gitlab/ci/config.rb', line 87

def normalized_jobs
  @normalized_jobs ||= Ci::Config::Normalizer.new(jobs).normalize_jobs
end

#stagesObject


79
80
81
# File 'lib/gitlab/ci/config.rb', line 79

def stages
  root.stages_value
end

#to_hashObject


64
65
66
# File 'lib/gitlab/ci/config.rb', line 64

def to_hash
  @config
end

#valid?Boolean

Returns:

  • (Boolean)

52
53
54
# File 'lib/gitlab/ci/config.rb', line 52

def valid?
  @root.valid?
end

#variablesObject

Temporary method that should be removed after refactoring


71
72
73
# File 'lib/gitlab/ci/config.rb', line 71

def variables
  root.variables_value
end

#variables_with_dataObject


75
76
77
# File 'lib/gitlab/ci/config.rb', line 75

def variables_with_data
  root.variables_entry.value_with_data
end

#warningsObject


60
61
62
# File 'lib/gitlab/ci/config.rb', line 60

def warnings
  @root.warnings
end