Commit 4662edd6 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab master

parents 15f83db7 9bc2b098
...@@ -1083,6 +1083,16 @@ module Ci ...@@ -1083,6 +1083,16 @@ module Ci
runner&.instance_type? runner&.instance_type?
end end
def job_variables_attributes
strong_memoize(:job_variables_attributes) do
job_variables.internal_source.map do |variable|
variable.attributes.except('id', 'job_id', 'encrypted_value', 'encrypted_value_iv').tap do |attrs|
attrs[:value] = variable.value
end
end
end
end
protected protected
def run_status_commit_hooks! def run_status_commit_hooks!
......
...@@ -68,7 +68,13 @@ module Ci ...@@ -68,7 +68,13 @@ module Ci
end end
def build_attributes(build) def build_attributes(build)
attributes = self.class.clone_accessors.to_h do |attribute| clone_attributes = if ::Feature.enabled?(:clone_job_variables_at_job_retry, build.project, default_enabled: :yaml)
self.class.clone_accessors + [:job_variables_attributes]
else
self.class.clone_accessors
end
attributes = clone_attributes.to_h do |attribute|
[attribute, build.public_send(attribute)] # rubocop:disable GitlabSecurity/PublicSend [attribute, build.public_send(attribute)] # rubocop:disable GitlabSecurity/PublicSend
end end
......
---
name: clone_job_variables_at_job_retry
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/75720
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/347156
milestone: '14.6'
type: development
group: group::pipeline authoring
default_enabled: false
...@@ -158,7 +158,7 @@ postgresql: ...@@ -158,7 +158,7 @@ postgresql:
memory: 1500M memory: 1500M
master: master:
nodeSelector: nodeSelector:
preemptible: "true" preemptible: "false"
prometheus: prometheus:
install: false install: false
redis: redis:
......
...@@ -73,6 +73,8 @@ RSpec.describe Ci::RetryBuildService do ...@@ -73,6 +73,8 @@ RSpec.describe Ci::RetryBuildService do
scheduled_at: 10.seconds.since) scheduled_at: 10.seconds.since)
end end
let_it_be(:internal_job_variable) { create(:ci_job_variable, job: build) }
before_all do before_all do
# Make sure that build has both `stage_id` and `stage` because FactoryBot # Make sure that build has both `stage_id` and `stage` because FactoryBot
# can reset one of the fields when assigning another. We plan to deprecate # can reset one of the fields when assigning another. We plan to deprecate
...@@ -86,7 +88,7 @@ RSpec.describe Ci::RetryBuildService do ...@@ -86,7 +88,7 @@ RSpec.describe Ci::RetryBuildService do
file_type: file_type, job: build, expire_at: build.artifacts_expire_at) file_type: file_type, job: build, expire_at: build.artifacts_expire_at)
end end
create(:ci_job_variable, job: build) create(:ci_job_variable, :dotenv_source, job: build)
create(:ci_build_need, build: build) create(:ci_build_need, build: build)
create(:terraform_state_version, build: build) create(:terraform_state_version, build: build)
end end
...@@ -125,6 +127,27 @@ RSpec.describe Ci::RetryBuildService do ...@@ -125,6 +127,27 @@ RSpec.describe Ci::RetryBuildService do
expect(new_build.needs_attributes).to match(build.needs_attributes) expect(new_build.needs_attributes).to match(build.needs_attributes)
expect(new_build.needs).not_to match(build.needs) expect(new_build.needs).not_to match(build.needs)
end end
context 'when clone_job_variables_at_job_retry is enabled' do
before do
stub_feature_flags(clone_job_variables_at_job_retry: true)
end
it 'clones only internal job variables' do
expect(new_build.job_variables.count).to eq(1)
expect(new_build.job_variables).to contain_exactly(having_attributes(key: internal_job_variable.key, value: internal_job_variable.value))
end
end
context 'when clone_job_variables_at_job_retry is not enabled' do
before do
stub_feature_flags(clone_job_variables_at_job_retry: false)
end
it 'does not clone internal job variables' do
expect(new_build.job_variables.count).to eq(0)
end
end
end end
describe 'reject accessors' do describe 'reject accessors' 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