Support variable expansion in environment.on_stop

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Release notes

Support variable expansion in environment.on_stop statements.

Problem to solve

Currently it's relatively easy to create dynamic environments using pipeline variables. That includes using parallel.matrix. However after creating such environments it's impossible to "stop" them automatically via on_stop as that requires references like: on_stop: stop_deployment-${INSTANCE}

As an example:

image: busybox

stages:
  - deploy
  - stop
  
deploy_job:
  stage: deploy
  script:
    - echo "Deploying ${INSTANCE}"
  environment: 
    name: &env_name my_env-${INSTANCE}
    on_stop: "stop_job: [${INSTANCE}]"
    auto_stop_in: 15m
  parallel:
    matrix:
      - INSTANCE: [1, 2, 3]

stop_job:
  stage: stop
  needs:
    - build_job
  script:
    - echo "Stopping ${INSTANCE}"
  environment:
    name: *env_name
    action: stop
  parallel:
    matrix:
      - INSTANCE: [1, 2, 3]

above example fails to execute with:

create_job: [1] job: on_stop job stop_job: [$INSTANCE] is not defined

Proposal

add support for variable interpolation into on_stop processing.

Intended users

Personas are described at https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/

Feature Usage Metrics

This page may contain information related to upcoming products, features and functionality. It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes. Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc.

Edited by 🤖 GitLab Bot 🤖