9

I run pipeline from a tag (let's say v1.0.0) on a branch (let's say staging). My output file is created with ${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}.apk. The result is a file named MyProject-v1.0.0.apk.

I wish add branch name in the output filename to get MyProject-staging-v1.0.0.apk.

From the gitlab documentation, i could use CI_COMMIT_TAG and CI_COMMIT_BRANCH like this ${CI_PROJECT_NAME}-${CI_COMMIT_BRANCH}-${CI_COMMIT_TAG}.apk. But the documentation says:

CI_COMMIT_BRANCH : The commit branch name. Present only when building branches.

CI_COMMIT_TAG : The commit tag name. Present only when building tags.

So how to get the branch name?

Troopers
  • 5,127
  • 1
  • 37
  • 64

2 Answers2

8

You can find which branch a tag is part of.

The issue is: a tag can be referenced (part of the history of) multiple branch.

So, as in here, your gitlab.yml could call a script setting that branch (settings an environment variable), provided you have a convention in place to select the branch you want out of the (possibly) more than one branch which could refer said tag.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Is there also a gitlab variable that always references the branch name, even if the pipeline is triggered on a tag? – Cord Kaldemeyer Jul 30 '21 at 13:58
  • @CordKaldemeyer I don't see one. You could ask a separate question, to be sure (and do add details about your setup, like OS and GitLab version). – VonC Jul 30 '21 at 14:07
  • 2
    I could solve my problem with your answer and have assigned an env var. Thanks a lot for your help! – Cord Kaldemeyer Aug 09 '21 at 11:43
-3

There is an env var called which references either the branch name or tag name called CI_COMMIT_REF_NAME