DRY project-level predefined variables
This commit is contained in:
parent
a4a29e2ee1
commit
0cf0a7a898
|
@ -257,12 +257,10 @@ module Ci
|
||||||
variables.concat(project.predefined_variables)
|
variables.concat(project.predefined_variables)
|
||||||
variables.concat(pipeline.predefined_variables)
|
variables.concat(pipeline.predefined_variables)
|
||||||
variables.concat(runner.predefined_variables) if runner
|
variables.concat(runner.predefined_variables) if runner
|
||||||
variables.concat(project.container_registry_variables)
|
|
||||||
variables.concat(project.deployment_variables) if has_environment?
|
variables.concat(project.deployment_variables) if has_environment?
|
||||||
variables.concat(project.auto_devops_variables)
|
|
||||||
variables.concat(yaml_variables)
|
variables.concat(yaml_variables)
|
||||||
variables.concat(user_variables)
|
variables.concat(user_variables)
|
||||||
variables.concat(project.group.secret_variables_for(ref, project).map(&:to_runner_variable)) if project.group
|
variables.concat(project.group.secret_variables_for(ref, project)) if project.group
|
||||||
variables.concat(secret_variables(environment: environment))
|
variables.concat(secret_variables(environment: environment))
|
||||||
variables.concat(trigger_request.user_variables) if trigger_request
|
variables.concat(trigger_request.user_variables) if trigger_request
|
||||||
variables.concat(pipeline.variables)
|
variables.concat(pipeline.variables)
|
||||||
|
|
|
@ -1581,21 +1581,21 @@ class Project < ActiveRecord::Base
|
||||||
variables.append(key: 'CI_PROJECT_NAMESPACE', value: namespace.full_path, public: true)
|
variables.append(key: 'CI_PROJECT_NAMESPACE', value: namespace.full_path, public: true)
|
||||||
variables.append(key: 'CI_PROJECT_URL', value: web_url, public: true)
|
variables.append(key: 'CI_PROJECT_URL', value: web_url, public: true)
|
||||||
variables.append(key: 'CI_PROJECT_VISIBILITY', value: visibility, public: true)
|
variables.append(key: 'CI_PROJECT_VISIBILITY', value: visibility, public: true)
|
||||||
|
variables.concat(container_registry_variables)
|
||||||
|
variables.concat(auto_devops_variables)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def container_registry_variables
|
def container_registry_variables
|
||||||
return [] unless Gitlab.config.registry.enabled
|
Gitlab::Ci::Variables::Collection.new.tap do |variables|
|
||||||
|
return variables unless Gitlab.config.registry.enabled
|
||||||
|
|
||||||
variables = [
|
variables.append(key: 'CI_REGISTRY', value: Gitlab.config.registry.host_port, public: true)
|
||||||
{ key: 'CI_REGISTRY', value: Gitlab.config.registry.host_port, public: true }
|
|
||||||
]
|
|
||||||
|
|
||||||
if container_registry_enabled?
|
if container_registry_enabled?
|
||||||
variables << { key: 'CI_REGISTRY_IMAGE', value: container_registry_url, public: true }
|
variables.append(key: 'CI_REGISTRY_IMAGE', value: container_registry_url, public: true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
variables
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def secret_variables_for(ref:, environment: nil)
|
def secret_variables_for(ref:, environment: nil)
|
||||||
|
@ -1624,7 +1624,7 @@ class Project < ActiveRecord::Base
|
||||||
def auto_devops_variables
|
def auto_devops_variables
|
||||||
return [] unless auto_devops_enabled?
|
return [] unless auto_devops_enabled?
|
||||||
|
|
||||||
(auto_devops || build_auto_devops)&.variables
|
(auto_devops || build_auto_devops)&.predefined_variables
|
||||||
end
|
end
|
||||||
|
|
||||||
def append_or_update_attribute(name, value)
|
def append_or_update_attribute(name, value)
|
||||||
|
|
|
@ -14,9 +14,11 @@ class ProjectAutoDevops < ActiveRecord::Base
|
||||||
domain.present? || instance_domain.present?
|
domain.present? || instance_domain.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def variables
|
def predefined_variables
|
||||||
variables = []
|
Gitlab::Ci::Variables::Collection.new.tap do |variables|
|
||||||
variables << { key: 'AUTO_DEVOPS_DOMAIN', value: domain.presence || instance_domain, public: true } if has_domain?
|
variables.append(key: 'AUTO_DEVOPS_DOMAIN',
|
||||||
variables
|
value: domain.presence || instance_domain,
|
||||||
|
public: true) if has_domain?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,6 +14,10 @@ module Gitlab
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def [](key)
|
||||||
|
@variable.fetch(key)
|
||||||
|
end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
to_hash == self.class.fabricate(other).to_hash
|
to_hash == self.class.fabricate(other).to_hash
|
||||||
end
|
end
|
||||||
|
@ -39,6 +43,8 @@ module Gitlab
|
||||||
self.new(resource.to_hash)
|
self.new(resource.to_hash)
|
||||||
when ::Ci::PipelineVariable
|
when ::Ci::PipelineVariable
|
||||||
self.new(resource.to_hash)
|
self.new(resource.to_hash)
|
||||||
|
when ::Ci::GroupVariable
|
||||||
|
self.new(resource.to_hash)
|
||||||
when self
|
when self
|
||||||
resource.dup
|
resource.dup
|
||||||
else
|
else
|
||||||
|
|
|
@ -36,14 +36,14 @@ describe ProjectAutoDevops do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#variables' do
|
describe '#predefined_variables' do
|
||||||
let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: domain) }
|
let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: domain) }
|
||||||
|
|
||||||
context 'when domain is defined' do
|
context 'when domain is defined' do
|
||||||
let(:domain) { 'example.com' }
|
let(:domain) { 'example.com' }
|
||||||
|
|
||||||
it 'returns AUTO_DEVOPS_DOMAIN' do
|
it 'returns AUTO_DEVOPS_DOMAIN' do
|
||||||
expect(auto_devops.variables).to include(domain_variable)
|
expect(auto_devops.predefined_variables).to include(domain_variable)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ describe ProjectAutoDevops do
|
||||||
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return('example.com')
|
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return('example.com')
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(auto_devops.variables).to include(domain_variable) }
|
it { expect(auto_devops.predefined_variables).to include(domain_variable) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when there is no instance domain specified' do
|
context 'when there is no instance domain specified' do
|
||||||
|
@ -63,7 +63,7 @@ describe ProjectAutoDevops do
|
||||||
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return(nil)
|
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(auto_devops.variables).not_to include(domain_variable) }
|
it { expect(auto_devops.predefined_variables).not_to include(domain_variable) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue