Commit 891a4821 authored by Matija Čupić's avatar Matija Čupić

Copy variables when retrying job

Changelog: changed
parent 44f0c50e
......@@ -1075,6 +1075,16 @@ module Ci
runner&.instance_type?
end
def job_variables_attributes
strong_memoize(:job_variables_attributes) do
job_variables.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
def run_status_commit_hooks!
......
......@@ -7,7 +7,7 @@ module Ci
allow_failure stage stage_id stage_idx trigger_request
yaml_variables when environment coverage_regex
description tag_list protected needs_attributes
resource_group scheduling_type].freeze
resource_group scheduling_type job_variables_attributes].freeze
end
def self.extra_accessors
......
......@@ -125,6 +125,14 @@ RSpec.describe Ci::RetryBuildService do
expect(new_build.needs_attributes).to match(build.needs_attributes)
expect(new_build.needs).not_to match(build.needs)
end
it 'clones only the job variables attributes' do
expect(new_build.job_variables.exists?).to be_truthy
expect(build.job_variables.exists?).to be_truthy
expect(new_build.job_variables_attributes).to match(build.job_variables_attributes)
expect(new_build.job_variables).not_to match(build.job_variables)
end
end
describe 'reject accessors' do
......@@ -147,7 +155,7 @@ RSpec.describe Ci::RetryBuildService do
Ci::Build.attribute_names.map(&:to_sym) +
Ci::Build.attribute_aliases.keys.map(&:to_sym) +
Ci::Build.reflect_on_all_associations.map(&:name) +
[:tag_list, :needs_attributes] -
[:tag_list, :needs_attributes, :job_variables_attributes] -
# ee-specific accessors should be tested in ee/spec/services/ci/retry_build_service_spec.rb instead
described_class.extra_accessors -
[:dast_site_profiles_build, :dast_scanner_profiles_build] # join tables
......
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