I need the tag value of my last pushed git commit in my gitlab-ci.yml when building. In the build process I build a docker image and after the build I want to push this images tagged with the same tag as my git commit. So far my understanding is that the environment variable $CI_COMMIT_TAG
should do the work. Nevertheless when I echo out $CI_COMMIT_TAG
in my gitlab-ci.yml is it just empty.
Here is my gitlab-ci.yml:
stages:
- build
build-dev:
stage: build
environment: development
only:
- master
tags:
- ms-doorman
script:
- echo $CI_COMMIT_TAG
Here the git commands to start the job.
$ git commit -am "test git tags"
$ git tag test-tag
$ git push --tags origin master
I found a nice issue in Gitlab which describes this behavior very well:
When you will push a commit to GitLab, then it will start a pipeline without CI_BUILD_TAG variable. When you make a tag on this commit and push this tag to GitLab, then another pipeline (this time for the tag, not for the commit) will be started. In that case CI_BUILD_TAG will be present.
Maybe you can use the workflow:rules to avoid the error.
only on tags:
rules:
- if: '$CI_COMMIT_TAG != null'
script:
- echo only on tags
- env
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With