summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrew <dscimino@gmail.com>2019-07-31 12:06:01 +0000
committerKamil TrzciƄski <ayufan@ayufan.eu>2019-07-31 12:06:01 +0000
commit5eb3c4af38959c3e9414053c954e397c0b03a26b (patch)
treefd0f6ba96bd21b223ece93ba6a7d37d329e719f8
parent252a0b0faa07160214e46e696cbfb0761e6f2a3d (diff)
downloadgitlab-ce-5eb3c4af38959c3e9414053c954e397c0b03a26b.tar.gz
Default dependency job stage index to Infinity, and correctly report it as undefined in prior stages
-rw-r--r--changelogs/unreleased/report-missing-job-dependency.yml6
-rw-r--r--lib/gitlab/ci/yaml_processor.rb4
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb25
3 files changed, 34 insertions, 1 deletions
diff --git a/changelogs/unreleased/report-missing-job-dependency.yml b/changelogs/unreleased/report-missing-job-dependency.yml
new file mode 100644
index 00000000000..660cdfc856e
--- /dev/null
+++ b/changelogs/unreleased/report-missing-job-dependency.yml
@@ -0,0 +1,6 @@
+---
+title: Default dependency job stage index to Infinity, and correctly report it as
+ undefined in prior stages
+merge_request: 31116
+author:
+type: fixed
diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb
index a5693dc4f81..a0bbf3c23a2 100644
--- a/lib/gitlab/ci/yaml_processor.rb
+++ b/lib/gitlab/ci/yaml_processor.rb
@@ -144,7 +144,9 @@ module Gitlab
job[:dependencies].each do |dependency|
raise ValidationError, "#{name} job: undefined dependency: #{dependency}" unless @jobs[dependency.to_sym]
- unless @stages.index(@jobs[dependency.to_sym][:stage]) < stage_index
+ dependency_stage_index = @stages.index(@jobs[dependency.to_sym][:stage])
+
+ unless dependency_stage_index.present? && dependency_stage_index < stage_index
raise ValidationError, "#{name} job: dependency #{dependency} is not defined in prior stages"
end
end
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index fc9d4f97bda..d3676ee03bf 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -1085,6 +1085,31 @@ module Gitlab
it { expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, 'test1 job: dependency deploy is not defined in prior stages') }
end
+
+ context 'when a job depends on another job that references a not-yet defined stage' do
+ let(:config) do
+ {
+ "stages" => [
+ "version"
+ ],
+ "version" => {
+ "stage" => "version",
+ "dependencies" => ["release:components:versioning"],
+ "script" => ["./versioning/versioning"]
+ },
+ ".release_go" => {
+ "stage" => "build",
+ "script" => ["cd versioning"]
+ },
+ "release:components:versioning" => {
+ "stage" => "build",
+ "script" => ["cd versioning"]
+ }
+ }
+ end
+
+ it { expect { subject }.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, /is not defined in prior stages/) }
+ end
end
describe "Hidden jobs" do