I’m assuming that CIRCLE_BRANCH is empty when the pipeline is triggered via tags. So I have created a bit of a clumsy piece using tag and commit id to determine the branch.
- run:
name: Determine commit ID & build branch
# determine branch from tag using commit ID.
# Note: "git branch -a --contains <tag>" could return multiple entries
# however, since the pipeline runs right after the tag is comminted
# this should not become an issue
command: COMMIT=$(git show-ref ${CIRCLE_TAG} | awk '{print $1}')
&& TMP=$(git branch -a --contains $COMMIT)
&& BRANCH="${TMP##*/}"
&& echo "Building branch $BRANCH"
Maybe this will be of use to someone else. Of course, any feedback and improvement suggestions are very welcome.
It is indeed expected that both the CIRCLE_BRANCH built-in environment variable and pipeline.git.branch pipeline value will be empty when your build is triggered by a tag-push.
- run:
name: Determine commit ID & build branch
# determine branch from tag using commit ID.
# Note: "git branch -a --contains <tag>" could return multiple entries
# however, since the pipeline runs right after the tag is comminted
# this should not become an issue
command: COMMIT=$(git show-ref | grep "${CIRCLE_TAG}" | awk '{print $1}')
&& TMP=$(git branch -a --contains $COMMIT)
&& BRANCH="${TMP##*/}"
&& echo "Building branch $BRANCH"