I would like to use 'BITBUCKET_COMMIT' variable in pipelines to create unique file name. The problem is, that 40-digits SHA is not convinient to use in file names.
Is it possible to use 7-digits SHA environment variables? Or any way to process it in YAML?
Hi Milosz,
You can truncate the BITBUCKET_COMMIT variable inside of your pipeline script.
For example:
pipelines:
default:
- step:
script:
- export BITBUCKET_COMMIT_SHORT=$(echo $BITBUCKET_COMMIT | cut -c1-7)
- ...
You can see other examples of how to do this here: https://stackoverflow.com/questions/8928224/trying-to-retrieve-first-5-characters-from-string-in-bash-error
Thanks,
Phil
Would be easier if pipelines would that work already for us. Also, for pipelines it would be easy to use git commands instead of bash tricks. Git has a "safety" mechanism that will make the short commit hashes it hands out longer if the default 7 chars are not unique.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, and no. We use BITBUCKET_COMMIT to compare it with git rev-parse. Now half a decade later I land here is because the variable randomly got shortened and does not equal to git rev-parse anymore :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As a quick ref, this works too for at least bash
export BITBUCKET_COMMIT_SHORT="${BITBUCKET_COMMIT::7}"
Details http://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion
Agree with @Alexander Weickmann
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What would be an equivalent for this in Windows Runners?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can get your git commit pretty format with the following:
- export COMMIT=$(git log --pretty=format:'%h' -n 1)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.