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:

stages:
  - deploy

deploy_dev:
  stage: deploy
  script:
    - env
  parallel:
    matrix:
      - PROJECT_NAME: a
      - PROJECT_NAME: b
      - PROJECT_NAME: c
        OTHER_VARIABLE: foo
      - PROJECT_NAME: d
  environment:
    name: $PROJECT_NAME
    # on_stop: stop_dev
  rules:
    - 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?

1 Like

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.

HTH,

Sarah

HI @sandra.tatarevicova ,

Did you manage to solve this? I have exactly the same problem.
I’ve tried printing out CI_JOB_NAME, but at the point when on_stop runs, it is set to ${job_name}

Alternative for me would be to pass all variables, from your example: [a, b, c, d], as an array to on_stop job and then iterate it with a script. But no luck so far