debian-mirror-gitlab/lib/gitlab/ci/config/external/file/artifact.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.5 KiB
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
class Config
module External
module File
class Artifact < Base
extend ::Gitlab::Utils::Override
include Gitlab::Utils::StrongMemoize
attr_reader :job_name
def initialize(params, context)
@location = params[:artifact]
@job_name = params[:job]
super
end
def content
strong_memoize(:content) do
Gitlab::Ci::ArtifactFileReader.new(artifact_job).read(location)
rescue Gitlab::Ci::ArtifactFileReader::Error => error
2023-06-20 00:43:36 +05:30
errors.push(error.message) # TODO this memoizes the error message as a content!
2020-04-08 14:13:33 +05:30
end
end
2022-06-21 17:19:12 +05:30
def metadata
super.merge(
type: :artifact,
location: masked_location,
extra: { job_name: masked_job_name }
)
end
2023-01-13 00:05:48 +05:30
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
2020-04-08 14:13:33 +05:30
end
2023-01-13 00:05:48 +05:30
end
2020-04-08 14:13:33 +05:30
2023-01-13 00:05:48 +05:30
def validate_content!
errors.push("File `#{masked_location}` is empty!") unless content.present?
2020-04-08 14:13:33 +05:30
end
2023-04-23 21:23:45 +05:30
private
2020-04-08 14:13:33 +05:30
def artifact_job
strong_memoize(:artifact_job) do
context.parent_pipeline.find_job_with_archive_artifacts(job_name)
end
end
def creating_child_pipeline?
context.parent_pipeline.present?
end
override :expand_context_attrs
def expand_context_attrs
{
project: context.project,
sha: context.sha,
user: context.user,
parent_pipeline: context.parent_pipeline
}
end
2022-06-21 17:19:12 +05:30
def masked_job_name
strong_memoize(:masked_job_name) do
context.mask_variables_from(job_name)
end
end
2020-04-08 14:13:33 +05:30
end
end
end
end
end
end