简体   繁体   中英

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 eg something_aef34a4x

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

GIT_COMMIT_SHORT_SHA was introduced in version 11.7: https://docs.gitlab.com/ce/ci/variables/

As you have discovered, currently gitlab.com has version 11.6.2 installed, so the variable is not available (yet).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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