I’m having trouble figuring out how (if it all) to get a short-form version of the $CI_COMMIT_SHA in .gitlab-ci.yml. Often a short-form commit SHA created with git rev-parse --short is used for referencing a commit, for example see how gitlab presents a shortened form of the commit SHA instead of the full-length one in the gitlab UI. I need that shortened form in my CI to name builds and other stuff in my CI/CD flow. The full commit SHA just doesn’t cut it because it’s too long.
Right now I have a before_script that does export SFSHA=$(git rev-parse --short=8 $CI_COMMIT_SHA) which makes the short-form commit SHA available in scripts, but it’s still not available outside of the scripts for use in environment urls and so on.
Is it possible to get a short-form commit SHA that is available in the whole runner? Is there already such a variable that I’ve just failed to discover?
git rev-parse --short HEAD ensures that the result does not collide - ie.: it will produce more characters if needed. If the CI_COMMIT_SHORT_SHA is simply the eight first characters it’s not a perfect replacement.