<p>Instead of hard-coding your branch name in <code>.gitlab-ci.yml</code> use <code>$CI_COMMIT_REF_NAME</code>. There are a bunch of pre-set environment variables you can use to get info about the current job.</p>
<p>The gitlab documentation has a list of them: <a href="https://docs.gitlab.com/ee/ci/variables/predefined_variables.html" rel="nofollow noreferrer">https://docs.gitlab.com/ee/ci/variables/predefined_variables.html</a></p>

CC BY-SA 4.0
2020-08-26T20:00:54.283Z
2020-08-26T20:00:54.283Z
bradym
<p>each step actually can run on each branch except you limit it with 'only' options. it will be more flexible to you. Please see this documentation section. <a href="https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-basic" rel="nofollow noreferrer">https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-basic</a></p>

CC BY-SA 4.0
2020-08-31T05:33:06.487Z
2020-08-31T05:33:06.487Z
Estu Fardani
<p>I have a nodeJS application which I deploy with Gitlab CI.
When pushing to branch XYZ, the corresponding script runs, let's assume on stage 'dev'. That's working.
So far so good.
Is it possible to select a specific branch so that instead of branch XYZ, e.g. Branch FOO can be deployed on 'dev' without having to change the gitlab-ci.yml file every time?</p>

<gitlab><cicd><gitlab-ci-runner>
Gitlab CI - Change branch dynamically
pkberlin
# Gitlab CI - Change branch dynamically

(Asked by: username_0 on 2020-08-26)

I have a nodeJS application which I deploy with Gitlab CI.
When pushing to branch XYZ, the corresponding script runs, let's assume on stage 'dev'. That's working.
So far so good.
Is it possible to select a specific branch so that instead of branch XYZ, e.g. Branch FOO can be deployed on 'dev' without having to change the gitlab-ci.yml file every time?

**Tags:** gitlab, cicd, gitlab-ci-runner


---

## 2 answers

### Answer by username_1 on 2020-08-26. Score: 1

Instead of hard-coding your branch name in `.gitlab-ci.yml` use `$CI_COMMIT_REF_NAME`. There are a bunch of pre-set environment variables you can use to get info about the current job.

The gitlab documentation has a list of them: <https://docs.gitlab.com/ee/ci/variables/predefined_variables.html>


---

### Answer by username_2 on 2020-08-31. Score: 0

each step actually can run on each branch except you limit it with 'only' options. it will be more flexible to you. Please see this documentation section. <https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-basic>


---

