diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-11-30 10:22:50 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2019-01-08 12:04:49 +0300 |
commit | f7de8922ddf579c5605706e64d962b716eef26e8 (patch) | |
tree | 511fb280d5d6b7c39eafb0167913a00c91d22213 | |
parent | 1d2ef4c6557846eb531f4d0e80cf43dea99b037b (diff) |
Drop persisted_environment from Ci::Builddrop-persisted-environment-in-ci-builds
-rw-r--r-- | app/models/ci/build.rb | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index dc6f8ae1a7f..5a1f9411aea 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -27,6 +27,7 @@ module Ci }.freeze has_one :deployment, as: :deployable, class_name: 'Deployment' + has_one :environment, through: :deployment, class_name: 'Environment' has_many :trace_sections, class_name: 'Ci::BuildTraceSection' has_many :trace_chunks, class_name: 'Ci::BuildTraceChunk', foreign_key: :build_id @@ -47,17 +48,6 @@ module Ci delegate :gitlab_deploy_token, to: :project delegate :trigger_short_token, to: :trigger_request, allow_nil: true - ## - # The "environment" field for builds is a String, and is the unexpanded name! - # - def persisted_environment - return unless has_environment? - - strong_memoize(:persisted_environment) do - Environment.find_by(name: expanded_environment_name, project: project) - end - end - serialize :options # rubocop:disable Cop/ActiveRecordSerialize serialize :yaml_variables, Gitlab::Serializer::Ci::Variables # rubocop:disable Cop/ActiveRecordSerialize @@ -353,12 +343,12 @@ module Ci return unless has_environment? strong_memoize(:expanded_environment_name) do - ExpandVariables.expand(environment, simple_variables) + ExpandVariables.expand(environment_value, simple_variables) end end def has_environment? - environment.present? + environment_value.present? end def starts_environment? @@ -894,9 +884,9 @@ module Ci def persisted_environment_variables Gitlab::Ci::Variables::Collection.new.tap do |variables| - break variables unless persisted? && persisted_environment.present? + break variables unless persisted? && environment.present? - variables.concat(persisted_environment.predefined_variables) + variables.concat(environment.predefined_variables) # Here we're passing unexpanded environment_url for runner to expand, # and we need to make sure that CI_ENVIRONMENT_NAME and @@ -915,7 +905,7 @@ module Ci end def environment_url - options&.dig(:environment, :url) || persisted_environment&.external_url + options&.dig(:environment, :url) || environment&.external_url end # The format of the retry option changed in GitLab 11.5: Before it was @@ -967,5 +957,9 @@ module Ci metadata&.write_attribute(metadata_key, nil) end end + + def environment_value + read_attribute(:environment) + end end end |