Commit 1aa37265 authored by Matija Čupić's avatar Matija Čupić

Validate against duplicates in job needs

Changelog: fixed
parent f8495767
......@@ -86,11 +86,19 @@ module Gitlab
def validate_job_needs!(name, job)
return unless needs = job.dig(:needs, :job)
validate_duplicate_needs!(name, needs)
needs.each do |need|
validate_job_dependency!(name, need[:name], 'need')
end
end
def validate_duplicate_needs!(name, needs)
unless needs.uniq == needs
error!("#{name} has duplicate entries in the needs section.")
end
end
def validate_job_dependency!(name, dependency, dependency_type = 'dependency')
unless @jobs[dependency.to_sym]
error!("#{name} job: undefined #{dependency_type}: #{dependency}")
......
......@@ -2097,6 +2097,12 @@ module Gitlab
it_behaves_like 'returns errors', 'test1 job: need deploy is not defined in current or prior stages'
end
context 'duplicate needs' do
let(:needs) { %w(build1 build1) }
it_behaves_like 'returns errors', 'test1 has duplicate entries in the needs section.'
end
context 'needs and dependencies that are mismatching' do
let(:needs) { %w(build1) }
let(:dependencies) { %w(build2) }
......
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