Commit 9492fd9c authored by Fabio Pitino's avatar Fabio Pitino

Fix bug when exposing non existing artifacts

When `expose_as` is used and no artifacts have been
uploaded it raises an unexpected error.
parent bbbc58a1
...@@ -46,6 +46,8 @@ module Ci ...@@ -46,6 +46,8 @@ module Ci
# it could contain many. We only need to know whether it has 1 or more # it could contain many. We only need to know whether it has 1 or more
# artifacts, so fetching the first 2 would be sufficient. # artifacts, so fetching the first 2 would be sufficient.
def first_2_metadata_entries_for_artifacts_paths(job) def first_2_metadata_entries_for_artifacts_paths(job)
return [] unless job.artifacts_metadata
job.artifacts_paths job.artifacts_paths
.lazy .lazy
.map { |path| job.artifacts_metadata_entry(path, recursive: true) } .map { |path| job.artifacts_metadata_entry(path, recursive: true) }
......
---
title: Fix bug when trying to expose artifacts and no artifacts are produced by the job
merge_request: 22378
author:
type: fixed
...@@ -50,10 +50,39 @@ describe Ci::FindExposedArtifactsService do ...@@ -50,10 +50,39 @@ describe Ci::FindExposedArtifactsService do
end end
end end
shared_examples 'does not find any matches' do
it 'returns empty array' do
expect(subject).to eq []
end
end
let_it_be(:pipeline) { create(:ci_pipeline, project: project) } let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
subject { described_class.new(project, user).for_pipeline(pipeline) } subject { described_class.new(project, user).for_pipeline(pipeline) }
context 'with jobs having no exposed artifacts' do
let!(:job) do
create_job_with_artifacts(artifacts: {
paths: ['other_artifacts_0.1.2/doc_sample.txt', 'something-else.html']
})
end
it_behaves_like 'does not find any matches'
end
context 'with jobs having no artifacts (metadata)' do
let!(:job) do
create(:ci_build, pipeline: pipeline, options: {
artifacts: {
expose_as: 'Exposed artifact',
paths: ['other_artifacts_0.1.2/doc_sample.txt', 'something-else.html']
}
})
end
it_behaves_like 'does not find any matches'
end
context 'with jobs having at most 1 matching exposed artifact' do context 'with jobs having at most 1 matching exposed artifact' do
let!(:job) do let!(:job) do
create_job_with_artifacts(artifacts: { create_job_with_artifacts(artifacts: {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment