Commit 98b60ee2 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Expand with all the variables so that things like

CI_ENVIRONMENT_SLUG is also available. It won't be
recursive because we're not putting this value in the variables.
parent 0d3631ac
...@@ -498,11 +498,7 @@ module Ci ...@@ -498,11 +498,7 @@ module Ci
end end
def environment_url def environment_url
return @environment_url if defined?(@environment_url) options&.dig(:environment, :url) || persisted_environment&.external_url
@environment_url =
options&.dig(:environment, :url) ||
persisted_environment&.external_url
end end
def build_attributes_from_config def build_attributes_from_config
......
...@@ -2,7 +2,7 @@ class CreateDeploymentService ...@@ -2,7 +2,7 @@ class CreateDeploymentService
attr_reader :job attr_reader :job
delegate :expanded_environment_name, delegate :expanded_environment_name,
:simple_variables, :variables,
:project, :project,
to: :job to: :job
...@@ -14,8 +14,10 @@ class CreateDeploymentService ...@@ -14,8 +14,10 @@ class CreateDeploymentService
return unless executable? return unless executable?
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
environment.external_url = expanded_environment_url if if external_url = expanded_environment_url
expanded_environment_url environment.external_url = external_url
end
environment.fire_state_event(action) environment.fire_state_event(action)
return unless environment.save return unless environment.save
...@@ -51,14 +53,8 @@ class CreateDeploymentService ...@@ -51,14 +53,8 @@ class CreateDeploymentService
end end
def expanded_environment_url def expanded_environment_url
return @expanded_environment_url if defined?(@expanded_environment_url) ExpandVariables.expand(environment_options[:url], variables) if
environment_options[:url]
@expanded_environment_url =
if unexpanded_url = environment_options[:url]
ExpandVariables.expand(unexpanded_url, simple_variables)
else
environment&.external_url
end
end end
def on_stop def on_stop
......
...@@ -135,6 +135,25 @@ describe CreateDeploymentService, services: true do ...@@ -135,6 +135,25 @@ describe CreateDeploymentService, services: true do
it { is_expected.to eq('http://review/master') } it { is_expected.to eq('http://review/master') }
end end
context 'when yaml environment uses $CI_ENVIRONMENT_SLUG' do
let(:job) do
create(:ci_build,
ref: 'master',
environment: 'production',
options: { environment: { url: 'http://review/$CI_ENVIRONMENT_SLUG' } })
end
let!(:environment) do
create(:environment,
project: job.project,
name: 'production',
slug: 'prod-slug',
external_url: 'http://review/old')
end
it { is_expected.to eq('http://review/prod-slug') }
end
context 'when yaml environment uses yaml_variables containing symbol keys' do context 'when yaml environment uses yaml_variables containing symbol keys' do
let(:job) do let(:job) do
create(:ci_build, create(:ci_build,
...@@ -153,7 +172,7 @@ describe CreateDeploymentService, services: true do ...@@ -153,7 +172,7 @@ describe CreateDeploymentService, services: true do
end end
it 'returns the external_url from persisted environment' do it 'returns the external_url from persisted environment' do
is_expected.to eq(environment.external_url) is_expected.to be_nil
end end
end end
end end
......
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