diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-03 18:09:56 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-03 18:09:56 +0300 |
commit | c08d9c22569d1c9e7c7737e183969593394133d9 (patch) | |
tree | 8ce1722f852f8921656080e04f6c9e16fa71ddb5 /lib/gitlab/ci/yaml_processor.rb | |
parent | 546ddc3f6ac96fdf09934390a938bb391d07dc94 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/ci/yaml_processor.rb')
-rw-r--r-- | lib/gitlab/ci/yaml_processor.rb | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb index 764047dae6d..4b0062549f0 100644 --- a/lib/gitlab/ci/yaml_processor.rb +++ b/lib/gitlab/ci/yaml_processor.rb @@ -142,6 +142,7 @@ 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 @@ -163,37 +164,52 @@ module Gitlab def validate_job_dependencies!(name, job) return unless job[:dependencies] - stage_index = @stages.index(job[:stage]) - job[:dependencies].each do |dependency| - raise ValidationError, "#{name} job: undefined dependency: #{dependency}" unless @jobs[dependency.to_sym] + validate_job_dependency!(name, dependency) + end + end - dependency_stage_index = @stages.index(@jobs[dependency.to_sym][:stage]) + def validate_dynamic_child_pipeline_dependencies!(name, job) + return unless includes = job.dig(:trigger, :include) - unless dependency_stage_index.present? && dependency_stage_index < stage_index - raise ValidationError, "#{name} job: dependency #{dependency} is not defined in prior stages" - end + includes.each do |included| + next unless dependency = included[:job] + + validate_job_dependency!(name, dependency) end end def validate_job_needs!(name, job) - return unless job.dig(:needs, :job) - - stage_index = @stages.index(job[:stage]) + return unless needs = job.dig(:needs, :job) - job.dig(:needs, :job).each do |need| - need_job_name = need[:name] + needs.each do |need| + dependency = need[:name] + validate_job_dependency!(name, dependency, 'need') + end + end - raise ValidationError, "#{name} job: undefined need: #{need_job_name}" unless @jobs[need_job_name.to_sym] + def validate_job_dependency!(name, dependency, dependency_type = 'dependency') + unless @jobs[dependency.to_sym] + raise ValidationError, "#{name} job: undefined #{dependency_type}: #{dependency}" + end - needs_stage_index = @stages.index(@jobs[need_job_name.to_sym][:stage]) + job_stage_index = stage_index(name) + dependency_stage_index = stage_index(dependency) - 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 + # 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 + def stage_index(name) + job = @jobs[name.to_sym] + return unless job + + @stages.index(job[:stage]) + end + def validate_job_environment!(name, job) return unless job[:environment] return unless job[:environment].is_a?(Hash) |