GitLab CI Branch Environment Variable

In CI, how does one know what branch the current build is being performed for.

We’d like to use the branch per environment model for CI deploys.
I’m having difficulty in CI with knowing what branch is really being deployed.

The CI_BUILD_REF_NAME cannot be used, because it will contain the Git TAG value rather than the Branch if a Git Tab is specified…

Is there another CI Build parameter that always contains the Branch?
I imagine I’m missing something obvious here.

Did you try and list all environment variables with export command? Just say"export" in a job, perhaps it has something you can use.

How about adding this to your script:
BRANCH=$(git rev-parse --abbrev-ref HEAD)

I haven’t tried it in CI, but it works if you’re in a plain git repo. I imagine it would work in CI, too.

Dave