summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-01-10 15:00:05 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-01-25 10:32:40 +0100
commit5d85a04927a1bb435e18c637b845d0e11613d9e4 (patch)
tree42e066354bd82d77095127ad5da8a32d4f5fba5a
parent5692c282afe15ca0c8e99568984e48b4b7b4109a (diff)
downloadgitlab-ce-5d85a04927a1bb435e18c637b845d0e11613d9e4.tar.gz
Make it possible to fabricate CI/CD bridge jobs
-rw-r--r--lib/gitlab/ci/pipeline/seed/build.rb10
-rw-r--r--lib/gitlab/ci/pipeline/seed/stage.rb8
-rw-r--r--lib/gitlab/ci/yaml_processor.rb5
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/build_spec.rb44
-rw-r--r--spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb14
5 files changed, 70 insertions, 11 deletions
diff --git a/lib/gitlab/ci/pipeline/seed/build.rb b/lib/gitlab/ci/pipeline/seed/build.rb
index ef738a93bfe..d8296940a04 100644
--- a/lib/gitlab/ci/pipeline/seed/build.rb
+++ b/lib/gitlab/ci/pipeline/seed/build.rb
@@ -38,9 +38,17 @@ module Gitlab
)
end
+ def bridge?
+ @attributes.to_h.dig(:options, :trigger).present?
+ end
+
def to_resource
strong_memoize(:resource) do
- ::Ci::Build.new(attributes)
+ if bridge?
+ ::Ci::Bridge.new(attributes)
+ else
+ ::Ci::Build.new(attributes)
+ end
end
end
end
diff --git a/lib/gitlab/ci/pipeline/seed/stage.rb b/lib/gitlab/ci/pipeline/seed/stage.rb
index 4775ff15581..015ca61d726 100644
--- a/lib/gitlab/ci/pipeline/seed/stage.rb
+++ b/lib/gitlab/ci/pipeline/seed/stage.rb
@@ -39,7 +39,13 @@ module Gitlab
def to_resource
strong_memoize(:stage) do
::Ci::Stage.new(attributes).tap do |stage|
- seeds.each { |seed| stage.builds << seed.to_resource }
+ seeds.each do |seed|
+ if seed.bridge?
+ stage.statuses << seed.to_resource
+ else
+ stage.builds << seed.to_resource
+ end
+ end
end
end
end
diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb
index 0c48a6ab3ac..5515092ccf1 100644
--- a/lib/gitlab/ci/yaml_processor.rb
+++ b/lib/gitlab/ci/yaml_processor.rb
@@ -33,7 +33,7 @@ module Gitlab
{ stage_idx: @stages.index(job[:stage]),
stage: job[:stage],
- tag_list: job[:tags] || [],
+ tag_list: job[:tags],
name: job[:name].to_s,
allow_failure: job[:ignore],
when: job[:when] || 'on_success',
@@ -53,7 +53,8 @@ module Gitlab
retry: job[:retry],
parallel: job[:parallel],
instance: job[:instance],
- start_in: job[:start_in]
+ start_in: job[:start_in],
+ trigger: job[:trigger]
}.compact }
end
diff --git a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
index a700cfd4546..fae8add6453 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
@@ -5,8 +5,7 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
let(:attributes) do
- { name: 'rspec',
- ref: 'master' }
+ { name: 'rspec', ref: 'master' }
end
subject do
@@ -21,10 +20,45 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
end
end
+ describe '#bridge?' do
+ context 'when job is a bridge' do
+ let(:attributes) do
+ { name: 'rspec', ref: 'master', options: { trigger: 'my/project' } }
+ end
+
+ it { is_expected.to be_bridge }
+ end
+
+ context 'when trigger definition is empty' do
+ let(:attributes) do
+ { name: 'rspec', ref: 'master', options: { trigger: '' } }
+ end
+
+ it { is_expected.not_to be_bridge }
+ end
+
+ context 'when job is not a bridge' do
+ it { is_expected.not_to be_bridge }
+ end
+ end
+
describe '#to_resource' do
- it 'returns a valid build resource' do
- expect(subject.to_resource).to be_a(::Ci::Build)
- expect(subject.to_resource).to be_valid
+ context 'when job is not a bridge' do
+ it 'returns a valid build resource' do
+ expect(subject.to_resource).to be_a(::Ci::Build)
+ expect(subject.to_resource).to be_valid
+ end
+ end
+
+ context 'when job is a bridge' do
+ let(:attributes) do
+ { name: 'rspec', ref: 'master', options: { trigger: 'my/project' } }
+ end
+
+ it 'returns a valid bridge resource' do
+ expect(subject.to_resource).to be_a(::Ci::Bridge)
+ expect(subject.to_resource).to be_valid
+ end
end
it 'memoizes a resource object' do
diff --git a/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
index 82f741845db..493ca3cd7b5 100644
--- a/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
@@ -62,8 +62,18 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
expect(subject.seeds.map(&:attributes)).to all(include(ref: 'master'))
expect(subject.seeds.map(&:attributes)).to all(include(tag: false))
expect(subject.seeds.map(&:attributes)).to all(include(project: pipeline.project))
- expect(subject.seeds.map(&:attributes))
- .to all(include(trigger_request: pipeline.trigger_requests.first))
+ end
+
+ context 'when a legacy trigger exists' do
+ before do
+ create(:ci_trigger_request, pipeline: pipeline)
+ end
+
+ it 'returns build seeds including legacy trigger' do
+ expect(pipeline.legacy_trigger).not_to be_nil
+ expect(subject.seeds.map(&:attributes))
+ .to all(include(trigger_request: pipeline.legacy_trigger))
+ end
end
context 'when a ref is protected' do