Gitlab-ci.yml: using job variables in the environment name doesn't work

In my gitlab-ci.yml file I’m using a template job that defines an empty job variable, let’s call it MY_VAR. I use this variable both in the artifact name and the environment name. Later, in an actual job where I map merge that template I change this variable. I expected that both the artifact and the environment would have the name of that variable but actually only the artifact has this name. Did I find a bug or is this behavior expected?

Example yaml file:

.template: &temp
  script:
  - echo
  variables:
    MY_VAR: ""
  artifacts:
    name: test$MY_VAR
    paths:
    - test
  environment:
    name: test/$MY_VAR

actual_job:
  <<: *temp
  variables:
    MY_VAR: "job1"

Edit: I should probably mention we are using GitLab Community Edition 8.14.4 and the gitlab-ci-multi-runner 1.8.0

I encountered a similar problem:

.template: &temp
 environment:
   name: $NAME
   url:  $URL


actual_job:
  <<: *temp
  variables:
    NAME: "job1"
    URL : "https://test.com"

returning in gitlab-ci lint

Status: syntax is incorrect
Error: jobs:actual_job:environment url must be a valid url

during my investigations & testing of gitlab-ci (using gitlab CE 8.13.1 and gitlab-ci-multi-runner 1.11.1).
Have you found any solution to this issue? (update excepted)

note: I just tested it on gitlab.com (EE 8.17.2 (I couldn’t get the runner version, sorry) ) and no error is triggered.

I am also interested in this option. Is possible to use variables in templates?

Hey, Gitlab, hello from 2021! This is still an issue!

1 Like