Split expanded_environment_name away from variable expansion
The following discussion from !202162 (merged) should be addressed:
-
@fabiopitino started a discussion: Idea for a follow-up:
The problem with
expanded_environment_namemethod is that it has more than 1 responsibility:- It returns the name of the persisted environment.
- It expands the user-provided environment name using the job variables.
I think that these 2 responsibilities should be separate. The latter should be a method on its own that can also be reused in https://gitlab.com/gitlab-org/gitlab/-/blob/26c2e6302994dfa99b8cb567704b94d29b416c9c/lib/gitlab/ci/build/context/build.rb#L42 as SSoT:
module Ci::Deployable def expand_environment_name(environment) ExpandVariables.expand(environment, -> { simple_variables.sort_and_expand_all }) end # At this stage the "expanded" prefix is irrelevant from a domain perspective def environment_name return unless has_environment_keyword? if use_job_environment_for_expanded_environment_name? && job_environment&.expanded_environment_name.present? return job_environment.expanded_environment_name end metadata&.expanded_environment_name end endThen use explicitly
expand_environment_namewhen we don't havejob_environmentpersisted yet and useenvironment_nameafter a job is persisted.