Using the abbreviated version of the Github commit sha in current version of CircleCI

Is there a working way to get a shortened version of the commit sha when using $CIRCLE_SHA1? I’m attempting to change our Slack notifications to include the sha but the full 40 character sha is a bit obnoxious - the goal is to have it look similar to the Slack GIthub app’s notifications that include the abbreviated sha and a link to the commit.

Hey @asnider93

BASH substrings are useful for this

${str:position:length}

Example:

❯ SHA=$(git rev-parse HEAD)
❯ SHORTSHA="${SHA:0:7}"
❯ echo $SHORTSHA
0b18930

It is important to note that if you need the “official” short commit hash, its length may vary, depending on what git requires to guarantee its uniqueness. so git rev-parse --short is the thing to use if you care about consistency with other tools (unless they’re also hard-coding it).