summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelogs/unreleased/persist-needs-error.yml5
-rw-r--r--lib/gitlab/ci/pipeline/chain/helpers.rb7
-rw-r--r--lib/gitlab/ci/pipeline/chain/populate.rb2
-rw-r--r--spec/services/ci/create_pipeline_service_spec.rb24
4 files changed, 32 insertions, 6 deletions
diff --git a/changelogs/unreleased/persist-needs-error.yml b/changelogs/unreleased/persist-needs-error.yml
new file mode 100644
index 00000000000..96aaa4d11a3
--- /dev/null
+++ b/changelogs/unreleased/persist-needs-error.yml
@@ -0,0 +1,5 @@
+---
+title: Persist `needs:` validation as config error
+merge_request:
+author:
+type: fixed
diff --git a/lib/gitlab/ci/pipeline/chain/helpers.rb b/lib/gitlab/ci/pipeline/chain/helpers.rb
index 6bb3a75291b..8ccb1066575 100644
--- a/lib/gitlab/ci/pipeline/chain/helpers.rb
+++ b/lib/gitlab/ci/pipeline/chain/helpers.rb
@@ -5,7 +5,12 @@ module Gitlab
module Pipeline
module Chain
module Helpers
- def error(message)
+ def error(message, config_error: false)
+ if config_error && command.save_incompleted
+ pipeline.yaml_errors = message
+ pipeline.drop!(:config_error)
+ end
+
pipeline.errors.add(:base, message)
end
end
diff --git a/lib/gitlab/ci/pipeline/chain/populate.rb b/lib/gitlab/ci/pipeline/chain/populate.rb
index 65029f5ce7f..13eca5a9d28 100644
--- a/lib/gitlab/ci/pipeline/chain/populate.rb
+++ b/lib/gitlab/ci/pipeline/chain/populate.rb
@@ -26,7 +26,7 @@ module Gitlab
# Gather all runtime build/stage errors
#
if seeds_errors = pipeline.stage_seeds.flat_map(&:errors).compact.presence
- return error(seeds_errors.join("\n"))
+ return error(seeds_errors.join("\n"), config_error: true)
end
##
diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb
index deb68899309..fad865a4811 100644
--- a/spec/services/ci/create_pipeline_service_spec.rb
+++ b/spec/services/ci/create_pipeline_service_spec.rb
@@ -1140,10 +1140,26 @@ describe Ci::CreatePipelineService do
context 'when pipeline on feature is created' do
let(:ref_name) { 'refs/heads/feature' }
- it 'does not create a pipeline as test_a depends on build_a' do
- expect(pipeline).not_to be_persisted
- expect(pipeline.builds).to be_empty
- expect(pipeline.errors[:base]).to contain_exactly("test_a: needs 'build_a'")
+ context 'when save_on_errors is enabled' do
+ let(:pipeline) { execute_service(save_on_errors: true) }
+
+ it 'does create a pipeline as test_a depends on build_a' do
+ expect(pipeline).to be_persisted
+ expect(pipeline.builds).to be_empty
+ expect(pipeline.yaml_errors).to eq("test_a: needs 'build_a'")
+ expect(pipeline.errors[:base]).to contain_exactly("test_a: needs 'build_a'")
+ end
+ end
+
+ context 'when save_on_errors is disabled' do
+ let(:pipeline) { execute_service(save_on_errors: false) }
+
+ it 'does not create a pipeline as test_a depends on build_a' do
+ expect(pipeline).not_to be_persisted
+ expect(pipeline.builds).to be_empty
+ expect(pipeline.yaml_errors).to be_nil
+ expect(pipeline.errors[:base]).to contain_exactly("test_a: needs 'build_a'")
+ end
end
end