gitlab-ci - Gitlab CI - $CI_COMMIT_TAG 为空

标签 gitlab-ci gitlab-ci-runner

构建时,我需要在 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/

相关文章:

gitlab - gitlab 中的自动发行说明

Docker 信任 : could not rotate trust to a new trusted root: failed to validate data with current trusted certificates

continuous-integration - Gitlab CI多个分支

gitlab - 获取 extends 关键字以在本地 gitlabci 运行器中工作

docker - gitlab-ci.yml部署在多个主机上

docker - Gitlab CI 将 Docker 构建拆分为多个阶段

gitlab-ci - 亚搏体育appCI : "Permission denied" when pulling private composer package

python - gitlab-ci.yml : 'script: -pytest' command is not recognized

gitlab - 在初始配置后更改 GitLab CI Multirunner 执行程序

java - 激活 Gitlab 以构建项目并运行测试的 .gitlab-ci.yml 文件应该是什么?