Class: Gitlab::Ci::Config::External::File::Artifact

Inherits:
Base
  • Object
show all
Extended by:
Utils::Override
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/config/external/file/artifact.rb

Constant Summary

Constants inherited from Base

Base::YAML_WHITELIST_EXTENSION

Instance Attribute Summary collapse

Attributes inherited from Base

#context, #errors, #location, #params

Instance Method Summary collapse

Methods included from Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods inherited from Base

#eql?, #error_message, #hash, #invalid_extension?, #invalid_location_type?, #load_and_validate_expanded_hash!, #matching?, #preload_content, #preload_context, #to_hash, #valid?, #validate_location!

Constructor Details

#initialize(params, context) ⇒ Artifact

Returns a new instance of Artifact.



14
15
16
17
18
19
# File 'lib/gitlab/ci/config/external/file/artifact.rb', line 14

def initialize(params, context)
  @location = params[:artifact]
  @job_name = params[:job]

  super
end

Instance Attribute Details

#job_nameObject (readonly)

Returns the value of attribute job_name.



12
13
14
# File 'lib/gitlab/ci/config/external/file/artifact.rb', line 12

def job_name
  @job_name
end

Instance Method Details

#contentObject



21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/ci/config/external/file/artifact.rb', line 21

def content
  return unless context.parent_pipeline.present?

  Gitlab::Ci::ArtifactFileReader.new(artifact_job).read(location)
rescue Gitlab::Ci::ArtifactFileReader::Error => error
  errors.push(error.message)

  nil
end

#metadataObject



32
33
34
35
36
37
38
# File 'lib/gitlab/ci/config/external/file/artifact.rb', line 32

def 
  super.merge(
    type: :artifact,
    location: masked_location,
    extra: { job_name: masked_job_name }
  )
end

#validate_content!Object



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

def validate_content!
  errors.push("File `#{masked_location}` is empty!") unless content.present?
end

#validate_context!Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gitlab/ci/config/external/file/artifact.rb', line 40

def validate_context!
  context.logger.instrument(:config_file_artifact_validate_context) do
    if !creating_child_pipeline?
      errors.push('Including configs from artifacts is only allowed when triggering child pipelines')
    elsif !job_name.present?
      errors.push("Job must be provided when including configs from artifacts")
    elsif !artifact_job.present?
      errors.push("Job `#{masked_job_name}` not found in parent pipeline or does not have artifacts!")
    end
  end
end