diff options
Diffstat (limited to 'lib/gitlab/ci/yaml_processor.rb')
-rw-r--r-- | lib/gitlab/ci/yaml_processor.rb | 50 |
1 files changed, 17 insertions, 33 deletions
diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb index 4b0062549f0..764047dae6d 100644 --- a/lib/gitlab/ci/yaml_processor.rb +++ b/lib/gitlab/ci/yaml_processor.rb @@ -142,7 +142,6 @@ module Gitlab validate_job_stage!(name, job) validate_job_dependencies!(name, job) validate_job_needs!(name, job) - validate_dynamic_child_pipeline_dependencies!(name, job) validate_job_environment!(name, job) end end @@ -164,50 +163,35 @@ module Gitlab def validate_job_dependencies!(name, job) return unless job[:dependencies] - job[:dependencies].each do |dependency| - validate_job_dependency!(name, dependency) - end - end + stage_index = @stages.index(job[:stage]) - def validate_dynamic_child_pipeline_dependencies!(name, job) - return unless includes = job.dig(:trigger, :include) + job[:dependencies].each do |dependency| + raise ValidationError, "#{name} job: undefined dependency: #{dependency}" unless @jobs[dependency.to_sym] - includes.each do |included| - next unless dependency = included[:job] + dependency_stage_index = @stages.index(@jobs[dependency.to_sym][:stage]) - validate_job_dependency!(name, dependency) + unless dependency_stage_index.present? && dependency_stage_index < stage_index + raise ValidationError, "#{name} job: dependency #{dependency} is not defined in prior stages" + end end end def validate_job_needs!(name, job) - return unless needs = job.dig(:needs, :job) + return unless job.dig(:needs, :job) - needs.each do |need| - dependency = need[:name] - validate_job_dependency!(name, dependency, 'need') - end - end + stage_index = @stages.index(job[:stage]) - def validate_job_dependency!(name, dependency, dependency_type = 'dependency') - unless @jobs[dependency.to_sym] - raise ValidationError, "#{name} job: undefined #{dependency_type}: #{dependency}" - end + job.dig(:needs, :job).each do |need| + need_job_name = need[:name] - job_stage_index = stage_index(name) - dependency_stage_index = stage_index(dependency) + raise ValidationError, "#{name} job: undefined need: #{need_job_name}" unless @jobs[need_job_name.to_sym] - # A dependency might be defined later in the configuration - # with a stage that does not exist - unless dependency_stage_index.present? && dependency_stage_index < job_stage_index - raise ValidationError, "#{name} job: #{dependency_type} #{dependency} is not defined in prior stages" - end - end + needs_stage_index = @stages.index(@jobs[need_job_name.to_sym][:stage]) - def stage_index(name) - job = @jobs[name.to_sym] - return unless job - - @stages.index(job[:stage]) + unless needs_stage_index.present? && needs_stage_index < stage_index + raise ValidationError, "#{name} job: need #{need_job_name} is not defined in prior stages" + end + end end def validate_job_environment!(name, job) |