Commit 666a6208 authored by Sean Arnold's avatar Sean Arnold

Merge branch 'lm-fix-pluck-config-entry-job' into 'master'

Add error for cross pipeline dependencies

See merge request gitlab-org/gitlab!80513
parents ac568b3e 2d2ff9dc
......@@ -37,10 +37,12 @@ module Gitlab
next unless dependencies.present?
next unless needs_value.present?
missing_needs = dependencies - needs_value[:job].pluck(:name) # rubocop:disable CodeReuse/ActiveRecord (Array#pluck)
if needs_value[:job].nil? && needs_value[:cross_dependency].present?
errors.add(:needs, "corresponding to dependencies must be from the same pipeline")
else
missing_needs = dependencies - needs_value[:job].pluck(:name) # rubocop:disable CodeReuse/ActiveRecord (Array#pluck)
if missing_needs.any?
errors.add(:dependencies, "the #{missing_needs.join(", ")} should be part of needs")
errors.add(:dependencies, "the #{missing_needs.join(", ")} should be part of needs") if missing_needs.any?
end
end
end
......
......@@ -420,7 +420,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job do
end
end
context 'when has dependencies' do
context 'when it has dependencies' do
context 'that are not a array of strings' do
let(:config) do
{ script: 'echo', dependencies: 'build-job' }
......@@ -433,8 +433,8 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job do
end
end
context 'when has needs' do
context 'when have dependencies that are not subset of needs' do
context 'when the job has needs' do
context 'and there are dependencies that are not included in needs' do
let(:config) do
{
stage: 'test',
......@@ -448,6 +448,24 @@ RSpec.describe Gitlab::Ci::Config::Entry::Job do
expect(entry).not_to be_valid
expect(entry.errors).to include 'job dependencies the another-job should be part of needs'
end
context 'and they are only cross pipeline needs' do
let(:config) do
{
script: 'echo',
dependencies: ['rspec'],
needs: [{
job: 'rspec',
pipeline: 'other'
}]
}
end
it 'adds an error for dependency keyword usage' do
expect(entry).not_to be_valid
expect(entry.errors).to include 'job needs corresponding to dependencies must be from the same pipeline'
end
end
end
end
......
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