BigW Consortium Gitlab

Commit 66edbc5e by Lin Jen-Shin

Introduce ci_environment_url which would fallback

to the external_url from persisted environment, and make the other utility methods private as we don't really need to use them outside of the job.
parent 4f8a1c0d
...@@ -138,13 +138,8 @@ module Ci ...@@ -138,13 +138,8 @@ module Ci
ExpandVariables.expand(environment, simple_variables) if environment ExpandVariables.expand(environment, simple_variables) if environment
end end
def expanded_environment_url def ci_environment_url
ExpandVariables.expand(environment_url, simple_variables) if expanded_environment_url || persisted_environment&.external_url
environment_url
end
def environment_url
options.dig(:environment, :url)
end end
def has_environment? def has_environment?
...@@ -506,14 +501,8 @@ module Ci ...@@ -506,14 +501,8 @@ module Ci
variables = persisted_environment.predefined_variables variables = persisted_environment.predefined_variables
if environment_url if url = ci_environment_url
variables << { key: 'CI_ENVIRONMENT_URL', variables << { key: 'CI_ENVIRONMENT_URL', value: url, public: true }
value: expanded_environment_url,
public: true }
elsif persisted_environment.external_url.present?
variables << { key: 'CI_ENVIRONMENT_URL',
value: persisted_environment.external_url,
public: true }
end end
variables variables
...@@ -537,6 +526,15 @@ module Ci ...@@ -537,6 +526,15 @@ module Ci
variables variables
end end
def expanded_environment_url
ExpandVariables.expand(environment_url, simple_variables) if
environment_url
end
def environment_url
options.dig(:environment, :url)
end
def build_attributes_from_config def build_attributes_from_config
return {} unless pipeline.config_processor return {} unless pipeline.config_processor
......
...@@ -427,11 +427,11 @@ describe Ci::Build, :models do ...@@ -427,11 +427,11 @@ describe Ci::Build, :models do
end end
end end
describe '#expanded_environment_url' do describe '#ci_environment_url' do
subject { build.expanded_environment_url } subject { job.ci_environment_url }
context 'when environment uses $CI_COMMIT_REF_NAME' do context 'when yaml environment uses $CI_COMMIT_REF_NAME' do
let(:build) do let(:job) do
create(:ci_build, create(:ci_build,
ref: 'master', ref: 'master',
options: { environment: { url: 'http://review/$CI_COMMIT_REF_NAME' } }) options: { environment: { url: 'http://review/$CI_COMMIT_REF_NAME' } })
...@@ -440,8 +440,8 @@ describe Ci::Build, :models do ...@@ -440,8 +440,8 @@ describe Ci::Build, :models do
it { is_expected.to eq('http://review/master') } it { is_expected.to eq('http://review/master') }
end end
context 'when environment uses yaml_variables containing symbol keys' do context 'when yaml environment uses yaml_variables containing symbol keys' do
let(:build) do let(:job) do
create(:ci_build, create(:ci_build,
yaml_variables: [{ key: :APP_HOST, value: 'host' }], yaml_variables: [{ key: :APP_HOST, value: 'host' }],
options: { environment: { url: 'http://review/$APP_HOST' } }) options: { environment: { url: 'http://review/$APP_HOST' } })
...@@ -449,6 +449,18 @@ describe Ci::Build, :models do ...@@ -449,6 +449,18 @@ describe Ci::Build, :models do
it { is_expected.to eq('http://review/host') } it { is_expected.to eq('http://review/host') }
end end
context 'when yaml environment does not have url' do
let(:job) { create(:ci_build, environment: 'staging') }
let!(:environment) do
create(:environment, project: job.project, name: job.environment)
end
it 'returns the external_url from persisted environment' do
is_expected.to eq(environment.external_url)
end
end
end end
describe '#starts_environment?' do describe '#starts_environment?' 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