dynamic job variables as part of dependencies name

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

  • Close this issue

Proposal

spawned from support ticket id (Internal ZD link)

We're setting up our gitlab ci pipeline and I wanted to encapsulate as many variables as possible.

In our repo we have multiple projects that follow the same build / deploy process, just with different variables to dictate; which folder, what env vars, software versions etc.

I managed to get the build jobs encapsulated like this;

api-docker-build-push-job:
  stage: build
  variables:
    project: "api"
    javaVersion: "8.0.282-open"
    envFile: "webioEnvTestApiServerVars.env"
  before_script:
    - !reference [.java-docker-build-push-job, before_script]
  script:
    - !reference [.java-docker-build-push-job, script]
  artifacts:
    paths:
      - $project/build/
  rules:
    - !reference [.java-docker-build-push-job, rules]

which is great, but my deploys look like this;

api-qa-docker-deploy-job:
  stage: qa
  variables:
    project: "api"
    deployEnv: "qa"
    cluster: "webioQaApp"
  before_script:
    - !reference [.java-docker-deploy-job, before_script]
  script:
    - !reference [.java-docker-deploy-job, script]
  dependencies:
    - api-docker-build-push-job
  rules:
    - !reference [.java-docker-deploy-job, rules]

So my issue is that when I want to duplicate this deploy job for another project, I'll be changing; the job name (fair enough) the project variable (cool) and then the dependencies section I have to put in the direct build job name; api-docker..... it'd be great if I could just use the project variable there like so;

api-qa-docker-deploy-job:
  stage: qa
  variables:
    project: "api"
    deployEnv: "qa"
    cluster: "webioQaApp"
  ...
  dependencies:
    - ${project}-docker-build-push-job
  ...

There's plenty of workarounds, but it's annoying, I'd prefer if it all slotted in at the gitlab-ci scope

Edited Sep 27, 2025 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading