首页 > 解决方案 > Are predefined variables in Gitlab CI/CD avaliable in .gitlab-ci.yml?

问题描述

I were trying to use CI_COMMIT_SHORT_SHA variable in config file (.gitlab-ci.yml), but it returned nothing.

I wanted to use CI_COMMIT_SHORT_SHA as part of directory name which were later pushed to the server by rsync. It should have returned short hash from current commit. Deployment passed successfully but the hash was empty.

deploy production:
    ...
    script:
        ...
        - VARIABLE_NAME=something_$CI_COMMIT_SHORT_SHA
        - echo $VARIABLE_NAME

Code above return just something_ instead of e.g. something_aef34a4x

So can I use CI_COMMIT_SHORT_SHA or other predefined variables like this at all or what is the right way?

标签: gitgitlabgitlab-ci

解决方案


GIT_COMMIT_SHORT_SHA在 11.7 版本中引入:https ://docs.gitlab.com/ce/ci/variables/

正如您所发现的,当前 gitlab.com 已安装 11.6.2 版本,因此该变量不可用(还)。


推荐阅读