简体   繁体   English

Gitlab CI / CD中的预定义变量在.gitlab-ci.yml中可用吗?

[英]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. 我试图在配置文件(.gitlab-ci.yml)中使用CI_COMMIT_SHORT_SHA变量,但是它什么也没返回。

I wanted to use CI_COMMIT_SHORT_SHA as part of directory name which were later pushed to the server by rsync. 我想使用CI_COMMIT_SHORT_SHA作为目录名的一部分,该目录名后来被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 eg something_aef34a4x 上面的代码仅返回something_而不是诸如something_aef34a4x

So can I use CI_COMMIT_SHORT_SHA or other predefined variables like this at all or what is the right way? 因此,我可以完全使用CI_COMMIT_SHORT_SHA或其他类似这样的预定义变量吗,或者正确的方法是什么?

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

As you have discovered, currently gitlab.com has version 11.6.2 installed, so the variable is not available (yet). 如您所知,当前gitlab.com已安装11.6.2版,因此该变量尚不可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM