Stop environment GIT_STRATEGY when we depend on global variables

As per
https://docs.gitlab.com/ee/ci/environments.html#viewing-environments-and-deployments
and,
https://docs.gitlab.com/ee/ci/yaml/#environment

In the example where we STOP an environment, the following text is quoted:

Setting the GIT_STRATEGY to none is necessary in the stop_review job so that the GitLab Runner won’t try to check out the code after the branch is deleted.

Also in the example, GIT_STRATEGY is set to none so that GitLab Runner won’t try to check out the code after the branch is deleted when the stop_review_app job is automatically triggered.

It does this in the STOP ENV job:

    stop_review:
      stage: deploy
      variables:
        GIT_STRATEGY: none            <<<< THIS
      script:
        - echo "Remove review app"
      when: manual
      environment:
        name: review/$CI_COMMIT_REF_NAME
        action: stop

However, what if our STOP ENV job depends on global variables? Setting this in the job will OVERWRITE the global variables.

https://docs.gitlab.com/ee/ci/yaml/#variables

When the variables keyword is used on a job level, it overrides the global YAML variables and predefined ones.

Is there no way to control the GIT strategy without wiping all global variables?

I think you can use YAML anchors to append variables on the base variables. For example,

.global-variables:
  variables: &base-variables
    FOO1: BAR1
    FOO2: BAR2

stop_review:
  stage: deploy
  variables:
    <<: *base-variables
    GIT_STRATEGY: none
  script:
    - echo "Remove review app"
  when: manual
  environment:
    name: review/$CI_COMMIT_REF_NAME
    action: stop

I’ve not tested this but once I saw the same technique used.

Is &base-variables some special key? (don’t see it mentioned in the docs) - ah I see, you label it as an anchor, trying this out

Excellent idea @shinya thank you! It worked.

Simply:

# global variables
variables: &base-variables
  FOO: foo
  BAR: bar
  ...

# a job that needs those variables AND git strategy none
stop_review:
  stage: deploy
  variables:
    <<: *base-variables
    GIT_STRATEGY: none
  script:
    - echo "Remove review app"
  when: manual
  environment:
    name: review/$CI_COMMIT_REF_NAME
    action: stop

Submitted a PR to improve documentation: https://gitlab.com/gitlab-org/gitlab/merge_requests/20556