Commit f45259d5 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'pedropombeiro/26345/7-report-sort-error-in-seed-build' into 'master'

Report any cyclic dep error when seeding build

See merge request gitlab-org/gitlab!54509
parents 95099ebb 3c558f21
...@@ -52,7 +52,7 @@ module Gitlab ...@@ -52,7 +52,7 @@ module Gitlab
return unless included? return unless included?
strong_memoize(:errors) do strong_memoize(:errors) do
needs_errors [needs_errors, variable_expansion_errors].compact.flatten
end end
end end
...@@ -153,6 +153,12 @@ module Gitlab ...@@ -153,6 +153,12 @@ module Gitlab
@pipeline.project.actual_limits.ci_needs_size_limit @pipeline.project.actual_limits.ci_needs_size_limit
end end
def variable_expansion_errors
sorted_collection = evaluate_context.variables.sorted_collection(@pipeline.project)
errors = sorted_collection.errors
["#{name}: #{errors}"] if errors
end
def pipeline_attributes def pipeline_attributes
{ {
pipeline: @pipeline, pipeline: @pipeline,
......
...@@ -1025,4 +1025,75 @@ RSpec.describe Gitlab::Ci::Pipeline::Seed::Build do ...@@ -1025,4 +1025,75 @@ RSpec.describe Gitlab::Ci::Pipeline::Seed::Build do
end end
end end
end end
describe 'applying pipeline variables' do
subject { seed_build }
let(:pipeline_variables) { [] }
let(:pipeline) do
build(:ci_empty_pipeline, project: project, sha: head_sha, variables: pipeline_variables)
end
context 'containing variable references' do
let(:pipeline_variables) do
[
build(:ci_pipeline_variable, key: 'A', value: '$B'),
build(:ci_pipeline_variable, key: 'B', value: '$C')
]
end
context 'when FF :variable_inside_variable is enabled' do
before do
stub_feature_flags(variable_inside_variable: [project])
end
it "does not have errors" do
expect(subject.errors).to be_empty
end
end
end
context 'containing cyclic reference' do
let(:pipeline_variables) do
[
build(:ci_pipeline_variable, key: 'A', value: '$B'),
build(:ci_pipeline_variable, key: 'B', value: '$C'),
build(:ci_pipeline_variable, key: 'C', value: '$A')
]
end
context 'when FF :variable_inside_variable is disabled' do
before do
stub_feature_flags(variable_inside_variable: false)
end
it "does not have errors" do
expect(subject.errors).to be_empty
end
end
context 'when FF :variable_inside_variable is enabled' do
before do
stub_feature_flags(variable_inside_variable: [project])
end
it "returns an error" do
expect(subject.errors).to contain_exactly(
'rspec: circular variable reference detected: ["A", "B", "C"]')
end
context 'with job:rules:[if:]' do
let(:attributes) { { name: 'rspec', ref: 'master', rules: [{ if: '$C != null', when: 'always' }] } }
it "included? does not raise" do
expect { subject.included? }.not_to raise_error
end
it "included? returns true" do
expect(subject.included?).to eq(true)
end
end
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment