Wouldn't it be great if you could use variables in tags?

I just noticed that tags can’t use variables expansion like for example;

    name: "$CI_COMMIT_REF_NAME"

Wouldn’t that be a great feature? Because then I could just use CI_COMMIT_REF_NAME the whole way from branch, to environment and to the runner running in that environment.

Makes sense to me, I’m surprised no one has suggested it.

Any other way to dynamically select the runner based on the branch name? I have public repos with private branches where this feature would be very helpful. I always want to share my code so everything I write for work is public, but it always has a private branch in our internal Gitlab.

So if I could use variables in tags I could have the same job template in the public branch as I do in the private branch.

Is perhaps an alternative solution to include something in the job file, so the include can be different based on if I’m in a public repo or in a private repo?

Hi @stefan.midjich
this was already requested in this issue, but it is not implemented, yet. If you have a paid plan you could contact GitLab support or your sales rep. You can also watch that issue to get any updates.

Here’s my workaround in case someone finds this topic.

    - echo "placeholder"

  local: '.gitlab-ci-*.yaml'

  extends: .standard_tags
  environment: "$CI_COMMIT_REF_NAME"

I can’t use CI_COMMIT_REF_NAME as a variable the whole way but I can still achieve what I set out to do.

So I have a public repo with a default branch. It has no file that matches .gitlab-ci-*.yml. Which is why I need the empty placeholder definition of .standard_tags first.

Then I have a private repo that contains .gitlab-ci-branch-name.yml and it looks like this;

    - branch-name

So branch-name in my case is the value of CI_COMMIT_REF_NAME but there is no way to use the variable the whole way so I have to hard code it. But since my private branches are all forked from the main branch I can have one file like this in each private branch that sets the tag so the correct runner is used.