Stopping environments deployed using parallel matrix jobs

We have a monorepo with more than 20 subprojects sharing the same code base. Our pipeline requirements are:

  • We want to be able to deploy each subproject separately.
  • We want to be able to stop each subproject separately.
  • We want to use GitLab Environments for development environments.

I have created a pipeline that basically looks like this:

  - deploy

  stage: deploy
    - env
      - PROJECT_NAME: a
      - PROJECT_NAME: b
      - PROJECT_NAME: c
        OTHER_VARIABLE: foo
      - PROJECT_NAME: d
    name: $PROJECT_NAME
    # on_stop: stop_dev
    - when: manual

The deploy job works as expected but I was not able to figure out how to stop the environments. I have noticed that when using the parallel matrix jobs, the CI_JOB_NAME is set to ${job_name}: [ ${matrix variables} ], but it is unfortunately not possible to use environment variables in the environment:on_stop key. Is it possible to somehow pass the PROJECT_NAME variable from the deploy_dev job to the stop_dev job or otherwise stop the environments separately?

Hi @sandra.tatarevicova

I would think that if your stop_dev script is a shell script, it will inherit the environment variables defined in the CI, so hopefully you can just use CI_JOB_NAME, and so on in that script.