Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,552,588
Community Members
 
Community Events
184
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

7 votes
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Mar 27, 2018

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

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 :(

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
AUG Leaders

Atlassian Community Events