diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-06-20 22:00:28 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-06-20 22:11:24 +0200 |
commit | 2e69ec6841bc60e70fa1db8e522978953ce55a18 (patch) | |
tree | d209c403268a289bd19ee159bc1d6efc39c1f269 | |
parent | dbfafd442ee863e6614d0f6765285fcd06f3d843 (diff) | |
download | gitlab-ce-fix-environment-url-to-contain-environment-slug.tar.gz |
Allow to expand environment_url to also allow to contain `CI_ENVIRONMENT_SLUG`.fix-environment-url-to-contain-environment-slug
-rw-r--r-- | app/models/ci/build.rb | 38 | ||||
-rw-r--r-- | app/services/create_deployment_service.rb | 7 |
2 files changed, 23 insertions, 22 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 58758f7ca8a..ae0ab5daf1b 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -139,14 +139,7 @@ module Ci end def environment_url - return @environment_url if defined?(@environment_url) - - @environment_url = - if unexpanded_url = options&.dig(:environment, :url) - ExpandVariables.expand(unexpanded_url, simple_variables) - else - persisted_environment&.external_url - end + options&.dig(:environment, :url) end def has_environment? @@ -194,17 +187,20 @@ module Ci # Variables whose value does not depend on other variables def simple_variables - variables = predefined_variables - variables += project.predefined_variables - variables += pipeline.predefined_variables - variables += runner.predefined_variables if runner - variables += project.container_registry_variables - variables += project.deployment_variables if has_environment? - variables += yaml_variables - variables += user_variables - variables += project.secret_variables_for(ref).map(&:to_runner_variable) - variables += trigger_request.user_variables if trigger_request - variables + return @simple_variables if defined?(@simple_variables) + + @simple_variables = predefined_variables + @simple_variables += legacy_variables + @simple_variables += project.predefined_variables + @simple_variables += pipeline.predefined_variables + @simple_variables += runner.predefined_variables if runner + @simple_variables += project.container_registry_variables + @simple_variables += project.deployment_variables if has_environment? + @simple_variables += yaml_variables + @simple_variables += user_variables + @simple_variables += project.secret_variables_for(ref).map(&:to_runner_variable) + @simple_variables += trigger_request.user_variables if trigger_request + @simple_variables end # All variables, including those dependent on other variables @@ -473,7 +469,7 @@ module Ci variables << { key: "CI_COMMIT_TAG", value: ref, public: true } if tag? variables << { key: "CI_PIPELINE_TRIGGERED", value: 'true', public: true } if trigger_request variables << { key: "CI_JOB_MANUAL", value: 'true', public: true } if action? - variables.concat(legacy_variables) + variables end def persisted_environment_variables @@ -481,7 +477,7 @@ module Ci variables = persisted_environment.predefined_variables - if url = environment_url + if url = environment_url || persisted_environment&.external_url variables << { key: 'CI_ENVIRONMENT_URL', value: url, public: true } end diff --git a/app/services/create_deployment_service.rb b/app/services/create_deployment_service.rb index 46823418bb0..afe9dcf0ec2 100644 --- a/app/services/create_deployment_service.rb +++ b/app/services/create_deployment_service.rb @@ -2,7 +2,6 @@ class CreateDeploymentService attr_reader :job delegate :expanded_environment_name, - :environment_url, :project, to: :job @@ -56,4 +55,10 @@ class CreateDeploymentService def action environment_options[:action] || 'start' end + + def environment_url + return unless environment_options[:url] + + @expanded_url ||= ExpandVariables.expand(environment_options[:url], variables) + end end |