Short SHA Hash Lengths for GIT
Different systems use different lengths for GIT Short SHA Hashes. Why is this important? Because sometimes in CICD things get mixed.
In one project, it is setup to build with skaffold, and while the kubernetes deployments are done using skaffold, the testing and on-premise deployments are done using docker-compose. As the Git Short SHA hash is used to tag the images in the build, it needs to be used when doing the other deployments. As it is different in different systems, it needs to be generated accordingly.
Gitlab
Gitlab provides CI_COMMIT_SHORT_SHA which is 8 characters.
To get a 9 character SHA hash use this:
short_sha = ${CI_COMMIT_SHA:0:9}
Skaffold
Skaffold uses 9 characters:
...
Generating tags...
- registry.gitlab.com/danielcaldwell/testgitlabcicd/testimage -> registry.gitlab.com/danielcaldwell/testgitlabcicd/testimage:863e41a24
...
Git log
Git log uses 9 characters
$ git log --oneline -n 10
5a9bfa1e4 (HEAD -> main) some change
3bd700b4d updated deploy image
915bfb39c fix: broken links to help docs.
a547fa73c tagged for build and deployment using gke