diff options
Diffstat (limited to 'lib/gitlab/ci')
-rw-r--r-- | lib/gitlab/ci/config/entry/include.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/ci/yaml_processor.rb | 48 |
2 files changed, 39 insertions, 17 deletions
diff --git a/lib/gitlab/ci/config/entry/include.rb b/lib/gitlab/ci/config/entry/include.rb index cd09d83b728..9c2e5f641d0 100644 --- a/lib/gitlab/ci/config/entry/include.rb +++ b/lib/gitlab/ci/config/entry/include.rb @@ -15,6 +15,14 @@ module Gitlab validations do validates :config, hash_or_string: true validates :config, allowed_keys: ALLOWED_KEYS + + validate do + next unless config.is_a?(Hash) + + if config[:artifact] && config[:job].blank? + errors.add(:config, "must specify the job where to fetch the artifact from") + end + end end end end diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb index 764047dae6d..933504ea82f 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,50 @@ 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 + Array(includes).each do |included| + next unless included.is_a?(Hash) + 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| + validate_job_dependency!(name, need[:name], '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) + stage = @jobs.dig(name.to_sym, :stage) + @stages.index(stage) + end + def validate_job_environment!(name, job) return unless job[:environment] return unless job[:environment].is_a?(Hash) |