构建时,我需要在 gitlab-ci.yml 中上次推送的 git commit 的标签值。在构建过程中,我构建了一个 docker 镜像,在构建之后,我想推送这些镜像,其标签与我的 git commit 相同。到目前为止我的理解是环境变量$CI_COMMIT_TAG
应该做的工作。尽管如此,当我回声时 $CI_COMMIT_TAG
在我的 gitlab-ci.yml 中它只是空的。
这是我的 gitlab-ci.yml:
stages:
- build
build-dev:
stage: build
environment: development
only:
- master
tags:
- ms-doorman
script:
- echo $CI_COMMIT_TAG
这里是启 Action 业的 git 命令。$ git commit -am "test git tags"
$ git tag test-tag
$ git push --tags origin master
最佳答案
我找到了一个不错的 issue在 Gitlab 中,它很好地描述了这种行为:
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.
也许你可以使用 workflow:rules以避免错误。
only on tags:
rules:
- if: '$CI_COMMIT_TAG != null'
script:
- echo only on tags
- env
关于gitlab-ci - Gitlab CI - $CI_COMMIT_TAG 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63370019/