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 ...@@ -48,18 +48,29 @@ module Gitlab
} }
end end
def name_with_details def name
vars = variables.map { |key, value| "#{key}=#{value}"}.join('; ') 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 end
def name def old_name
"#{job_name} #{instance}/#{total}" "#{job_name} #{instance}/#{total}"
end end
private
attr_reader :job_name, :instance, :variables, :total attr_reader :job_name, :instance, :variables, :total
end end
end end
......
...@@ -76,6 +76,10 @@ module Gitlab ...@@ -76,6 +76,10 @@ module Gitlab
Feature.enabled?(:project_transactionless_destroy, project, default_enabled: false) Feature.enabled?(:project_transactionless_destroy, project, default_enabled: false)
end end
def self.new_matrix_job_names_enabled?
::Feature.enabled?(:ci_matrix_job_names, default_enabled: false)
end
def self.coverage_report_view?(project) def self.coverage_report_view?(project)
::Feature.enabled?(:coverage_report_view, project) ::Feature.enabled?(:coverage_report_view, project)
end end
......
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do
describe '.applies_to?' do describe '.applies_to?' do
...@@ -39,6 +39,11 @@ RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do ...@@ -39,6 +39,11 @@ RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do
it { expect(subject.size).to eq(4) } it { expect(subject.size).to eq(4) }
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 it 'has attributes' do
expect(subject.map(&:attributes)).to match_array( expect(subject.map(&:attributes)).to match_array(
[ [
...@@ -87,16 +92,61 @@ RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do ...@@ -87,16 +92,61 @@ RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do
['test 1/4', 'test 2/4', 'test 3/4', 'test 4/4'] ['test 1/4', 'test 2/4', 'test 3/4', 'test 4/4']
) )
end end
end
it 'has details' do context 'with new_matrix_job_names_enabled ff enabled' do
expect(subject.map(&:name_with_details)).to match_array( before do
stub_feature_flags(ci_matrix_job_names: true)
end
it 'has attributes' do
expect(subject.map(&:attributes)).to match_array(
[ [
'test (PROVIDER=aws; STACK=app1)', {
'test (PROVIDER=aws; STACK=app2)', name: 'test: [aws, app1]',
'test (PROVIDER=gcp; STACK=app)', instance: 1,
'test (PROVIDER=ovh; STACK=app)' 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 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
end end
# frozen_string_literal: true # frozen_string_literal: true
require 'fast_spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::Normalizer do RSpec.describe Gitlab::Ci::Config::Normalizer do
let(:job_name) { :rspec } let(:job_name) { :rspec }
...@@ -178,39 +178,28 @@ RSpec.describe Gitlab::Ci::Config::Normalizer do ...@@ -178,39 +178,28 @@ RSpec.describe Gitlab::Ci::Config::Normalizer do
{ {
matrix: [ matrix: [
{ {
VAR_1: [1], VAR_1: ['A'],
VAR_2: [2, 3] VAR_2: %w[B C]
} }
] ]
} }
end end
let(:expanded_job_names) do
[
'rspec 1/2',
'rspec 2/2'
]
end
it 'does not have original job' do it 'does not have original job' do
is_expected.not_to include(job_name) is_expected.not_to include(job_name)
end end
it 'has parallelized jobs' do
is_expected.to include(*expanded_job_names.map(&:to_sym))
end
it 'sets job instance in options' do it 'sets job instance in options' do
expect(subject.values).to all(include(:instance)) expect(subject.values).to all(include(:instance))
end end
it 'sets job variables', :aggregate_failures do it 'sets job variables', :aggregate_failures do
expect(subject.values[0]).to match( 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( 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 end
...@@ -226,9 +215,46 @@ RSpec.describe Gitlab::Ci::Config::Normalizer do ...@@ -226,9 +215,46 @@ RSpec.describe Gitlab::Ci::Config::Normalizer do
expect(configs).to all(match(a_hash_including(original_config))) expect(configs).to all(match(a_hash_including(original_config)))
end end
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 dependencies'
it_behaves_like 'parallel needs' it_behaves_like 'parallel needs'
end end
end
context 'when parallel config does not matches a factory' do context 'when parallel config does not matches a factory' do
let(:variables_config) { {} } let(:variables_config) { {} }
......
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