Skip to main content

How to get a tag commit in CircleCI

Overview

In some cases, you may be triggering CircleCI off of a tagged commit via GitHub Actions, etc and you may need to retrieve the tag commit to tag your deployment.

If the CircleCI pipeline is not triggered via a Release, << pipeline.git.tag >> will be empty

Resolution

To get a tag that is from a commit, you can add the following step in your job.

- run: 
name: Get Tag from Commit
command: |
GIT_TAG=$(git log -n 1 --pretty=format:%s $CIRCLE_SHA | sed 's/[a-zA-Z() :]//g')
echo "export GIT_TAG=$GIT_TAG" >> "$BASH_ENV"

As an example, with this step, we can turn chore(release): 1.65.2 to 1.65.2 and it will be accessible via $GIT_TAG in your job.

Additional Resources

Did this answer your question?