Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,024
Community Members
 
Community Events
165
Community Groups

BITBUCKET_COMMIT variable - short (7digits) in pipelines

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?

3 answers

6 votes

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.

Like # people like this

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 

Best answer, in sh works too

You can get your git commit pretty format with the following:

- export COMMIT=$(git log --pretty=format:'%h' -n 1)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,222 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you