Commit 0efddbd5 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch '230452-show-relevant-values-in-job-name-for-matrix-builds' into 'master'

Show variables values in job name for matrix builds

See merge request gitlab-org/gitlab!39985
parents c1604e48 d679c570
---
name: ci_matrix_job_names
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/39985
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/239012
group: 'group::continuous integration'
type: development
default_enabled: false
......@@ -48,18 +48,29 @@ module Gitlab
}
end
def name_with_details
vars = variables.map { |key, value| "#{key}=#{value}"}.join('; ')
def name
if Gitlab::Ci::Features.new_matrix_job_names_enabled?
name_with_variable_details
else
old_name
end
end
private
"#{job_name} (#{vars})"
def name_with_variable_details
vars = variables
.values
.compact
.join(', ')
"#{job_name}: [#{vars}]"
end
def name
def old_name
"#{job_name} #{instance}/#{total}"
end
private
attr_reader :job_name, :instance, :variables, :total
end
end
......
......@@ -76,6 +76,10 @@ module Gitlab
Feature.enabled?(:project_transactionless_destroy, project, default_enabled: false)
end
def self.new_matrix_job_names_enabled?
::Feature.enabled?(:ci_matrix_job_names, default_enabled: false)
end
def self.coverage_report_view?(project)
::Feature.enabled?(:coverage_report_view, project)
end
......
# frozen_string_literal: true
require 'fast_spec_helper'
require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do
describe '.applies_to?' do
......@@ -39,64 +39,114 @@ RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do
it { expect(subject.size).to eq(4) }
it 'has attributes' do
expect(subject.map(&:attributes)).to match_array(
[
{
name: 'test 1/4',
instance: 1,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'aws',
'STACK' => 'app1'
}
},
{
name: 'test 2/4',
instance: 2,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'aws',
'STACK' => 'app2'
}
},
{
name: 'test 3/4',
instance: 3,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'ovh',
'STACK' => 'app'
}
},
{
name: 'test 4/4',
instance: 4,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'gcp',
'STACK' => 'app'
context 'with new_matrix_job_names_enabled ff disabled' do
before do
stub_feature_flags(ci_matrix_job_names: false)
end
it 'has attributes' do
expect(subject.map(&:attributes)).to match_array(
[
{
name: 'test 1/4',
instance: 1,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'aws',
'STACK' => 'app1'
}
},
{
name: 'test 2/4',
instance: 2,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'aws',
'STACK' => 'app2'
}
},
{
name: 'test 3/4',
instance: 3,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'ovh',
'STACK' => 'app'
}
},
{
name: 'test 4/4',
instance: 4,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'gcp',
'STACK' => 'app'
}
}
}
]
)
end
]
)
end
it 'has parallelized name' do
expect(subject.map(&:name)).to match_array(
['test 1/4', 'test 2/4', 'test 3/4', 'test 4/4']
)
it 'has parallelized name' do
expect(subject.map(&:name)).to match_array(
['test 1/4', 'test 2/4', 'test 3/4', 'test 4/4']
)
end
end
it 'has details' do
expect(subject.map(&:name_with_details)).to match_array(
[
'test (PROVIDER=aws; STACK=app1)',
'test (PROVIDER=aws; STACK=app2)',
'test (PROVIDER=gcp; STACK=app)',
'test (PROVIDER=ovh; STACK=app)'
]
)
context 'with new_matrix_job_names_enabled ff enabled' do
before do
stub_feature_flags(ci_matrix_job_names: true)
end
it 'has attributes' do
expect(subject.map(&:attributes)).to match_array(
[
{
name: 'test: [aws, app1]',
instance: 1,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'aws',
'STACK' => 'app1'
}
},
{
name: 'test: [aws, app2]',
instance: 2,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'aws',
'STACK' => 'app2'
}
},
{
name: 'test: [ovh, app]',
instance: 3,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'ovh',
'STACK' => 'app'
}
},
{
name: 'test: [gcp, app]',
instance: 4,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'gcp',
'STACK' => 'app'
}
}
]
)
end
it 'has parallelized name' do
expect(subject.map(&:name)).to match_array(
['test: [aws, app1]', 'test: [aws, app2]', 'test: [gcp, app]', 'test: [ovh, app]']
)
end
end
end
end
# frozen_string_literal: true
require 'fast_spec_helper'
require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::Normalizer do
let(:job_name) { :rspec }
......@@ -178,39 +178,28 @@ RSpec.describe Gitlab::Ci::Config::Normalizer do
{
matrix: [
{
VAR_1: [1],
VAR_2: [2, 3]
VAR_1: ['A'],
VAR_2: %w[B C]
}
]
}
end
let(:expanded_job_names) do
[
'rspec 1/2',
'rspec 2/2'
]
end
it 'does not have original job' do
is_expected.not_to include(job_name)
end
it 'has parallelized jobs' do
is_expected.to include(*expanded_job_names.map(&:to_sym))
end
it 'sets job instance in options' do
expect(subject.values).to all(include(:instance))
end
it 'sets job variables', :aggregate_failures do
expect(subject.values[0]).to match(
a_hash_including(variables: { VAR_1: 1, VAR_2: 2, USER_VARIABLE: 'user value' })
a_hash_including(variables: { VAR_1: 'A', VAR_2: 'B', USER_VARIABLE: 'user value' })
)
expect(subject.values[1]).to match(
a_hash_including(variables: { VAR_1: 1, VAR_2: 3, USER_VARIABLE: 'user value' })
a_hash_including(variables: { VAR_1: 'A', VAR_2: 'C', USER_VARIABLE: 'user value' })
)
end
......@@ -226,8 +215,45 @@ RSpec.describe Gitlab::Ci::Config::Normalizer do
expect(configs).to all(match(a_hash_including(original_config)))
end
it_behaves_like 'parallel dependencies'
it_behaves_like 'parallel needs'
context 'with new_matrix_job_names_enabled ff enabled' do
let(:expanded_job_names) do
[
'rspec: [A, B]',
'rspec: [A, C]'
]
end
before do
stub_feature_flags(ci_matrix_job_names: true)
end
it 'has parallelized jobs' do
is_expected.to include(*expanded_job_names.map(&:to_sym))
end
it_behaves_like 'parallel dependencies'
it_behaves_like 'parallel needs'
end
context 'with new_matrix_job_names_enabled ff disabled' do
let(:expanded_job_names) do
[
'rspec 1/2',
'rspec 2/2'
]
end
before do
stub_feature_flags(ci_matrix_job_names: false)
end
it 'has parallelized jobs' do
is_expected.to include(*expanded_job_names.map(&:to_sym))
end
it_behaves_like 'parallel dependencies'
it_behaves_like 'parallel needs'
end
end
context 'when parallel config does not matches a factory' do
......
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