Commit 535c2d3c authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'mc/feature/pipeline-tracking-config-ce' into 'master'

Add `needs:` CI config option CE

Closes gitlab-ee#12334

See merge request gitlab-org/gitlab-ce!31346
parents 94c7a93d 16084ee9
......@@ -328,6 +328,10 @@ module Ci
config_sources.values_at(:repository_source, :auto_devops_source, :unknown_source)
end
def self.bridgeable_statuses
::Ci::Pipeline::AVAILABLE_STATUSES - %w[created preparing pending]
end
def stages_count
statuses.select(:stage).distinct.count
end
......
......@@ -176,6 +176,21 @@ Upstream pipelines take precedence over downstream ones. If there are two
variables with the same name defined in both upstream and downstream projects,
the ones defined in the upstream project will take precedence.
### Mirroring status from upstream pipeline
You can mirror the pipeline status from an upstream pipeline to a bridge job by
using the `needs:pipeline` keyword. The latest pipeline status from master is
replicated to the bridge job.
Example:
```yaml
upstream_bridge:
stage: test
needs:
pipeline: other/project
```
### Limitations
Because bridge jobs are a little different to regular jobs, it is not
......
......@@ -57,7 +57,10 @@ module Gitlab
end
def bridge?
@attributes.to_h.dig(:options, :trigger).present?
attributes_hash = @attributes.to_h
attributes_hash.dig(:options, :trigger).present? ||
(attributes_hash.dig(:options, :bridge_needs).instance_of?(Hash) &&
attributes_hash.dig(:options, :bridge_needs, :pipeline).present?)
end
def to_resource
......
......@@ -55,7 +55,8 @@ module Gitlab
parallel: job[:parallel],
instance: job[:instance],
start_in: job[:start_in],
trigger: job[:trigger]
trigger: job[:trigger],
bridge_needs: job[:needs]
}.compact }.compact
end
......
......@@ -8,7 +8,7 @@ FactoryBot.define do
ref 'master'
tag false
created_at 'Di 29. Okt 09:50:00 CET 2013'
status :success
status :created
pipeline factory: :ci_pipeline
......@@ -17,6 +17,7 @@ FactoryBot.define do
end
transient { downstream nil }
transient { upstream nil }
after(:build) do |bridge, evaluator|
bridge.project ||= bridge.pipeline.project
......@@ -26,6 +27,12 @@ FactoryBot.define do
trigger: { project: evaluator.downstream.full_path }
)
end
if evaluator.upstream.present?
bridge.options = bridge.options.to_h.merge(
bridge_needs: { pipeline: evaluator.upstream.full_path }
)
end
end
end
end
......@@ -20,13 +20,12 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
describe '#bridge?' do
subject { seed_build.bridge? }
context 'when job is a bridge' do
context 'when job is a downstream bridge' do
let(:attributes) do
{ name: 'rspec', ref: 'master', options: { trigger: 'my/project' } }
end
it { is_expected.to be_truthy }
end
context 'when trigger definition is empty' do
let(:attributes) do
......@@ -35,6 +34,23 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
it { is_expected.to be_falsey }
end
end
context 'when job is an upstream bridge' do
let(:attributes) do
{ name: 'rspec', ref: 'master', options: { bridge_needs: { pipeline: 'my/project' } } }
end
it { is_expected.to be_truthy }
context 'when upstream definition is empty' do
let(:attributes) do
{ name: 'rspec', ref: 'master', options: { bridge_needs: { pipeline: '' } } }
end
it { is_expected.to be_falsey }
end
end
context 'when job is not a bridge' do
it { is_expected.to be_falsey }
......
......@@ -1153,7 +1153,10 @@ module Gitlab
stage_idx: 1,
name: "test1",
options: {
script: ["test"]
script: ["test"],
# This does not make sense, there is a follow-up:
# https://gitlab.com/gitlab-org/gitlab-ce/issues/65569
bridge_needs: %w[build1 build2]
},
needs_attributes: [
{ name: "build1" },
......
......@@ -23,7 +23,7 @@ describe Ci::Bridge do
let(:status) { bridge.detailed_status(user) }
it 'returns detailed status object' do
expect(status).to be_a Gitlab::Ci::Status::Success
expect(status).to be_a Gitlab::Ci::Status::Created
end
end
......
......@@ -1929,6 +1929,13 @@ describe Ci::Pipeline, :mailer do
it { is_expected.to be_an(Array) }
end
describe '.bridgeable_statuses' do
subject { described_class.bridgeable_statuses }
it { is_expected.to be_an(Array) }
it { is_expected.not_to include('created', 'preparing', 'pending') }
end
describe '#status' do
let(:build) do
create(:ci_build, :created, pipeline: pipeline, name: 'test')
......
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