how can I find out branch name in a job that is running in the pipeline?
I tried git branch
all i get is
* (detached from <commit number>)
master
Asked
Active
Viewed 930 times
3

lila
- 423
- 1
- 4
- 16
-
This means you are not on a specific branch any more but on a specific commit with no branch pointing to it. What do you run before? – Christos Batzilis Jun 07 '18 at 11:53
-
.gitlab-ci.yml script that runs in the pipeline. – lila Jun 07 '18 at 12:51
1 Answers
4
There is a predefined variable called CI_COMMIT_REF_NAME
that contains branch name. for more info here

Josh Correia
- 3,807
- 3
- 33
- 50

lila
- 423
- 1
- 4
- 16
-
1This is correct.Your can also use ${CI_COMMIT_REF_SLUG} if you want to escape some characters and get a kind of specific name based on the branch name. Check also ${CI_COMMIT_SHA} is you want to distinguish commits inside the same branch. – Mahnu Jun 08 '18 at 10:52