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,466,493
Community Members
 
Community Events
176
Community Groups

How do I get the commit SHA merged in in Pipelines pull-request builds?

Felix Atlassian Team Jun 10, 2022

I'm trying to set up a pull request build that calculates the files changed in a pull request on a certain path.

I'm trying to do this so that I can exercise any new tests introduced in the PR by running them multiple times (to ensure they are not flakey).

I know that the BITBUCKET_PR_DESTINATION_BRANCH variable exists, but it seems like that does not allow me to do what I want, because the merge that pipelines does for a pull-request build is not always the tip of the destination branch.

If the merge commit that happens on that build produces a merge, I can get the commit SHA using:

git rev-list --parents -n 1 HEAD | cut -d " " -f 3

I use that to grab the files like this:

git diff --name-only HEAD $(git rev-list --parents -n 1 HEAD | cut -d " " -f 3) -- test/

However, if the pull-request branch is up to date with the destination branch, no merge commit is produced, and the above does not work.


Is there any way to get the commit SHA Bitbucket Pipelines uses in the Build setup?

Or another easy way to produce a list of the changed files of a certain path in that PR?

Screen Shot 2022-06-10 at 2.54.08 PM.png

1 answer

0 votes
Patrik S Atlassian Team Jun 14, 2022

Hello @Felix ,

Welcome to Atlassian Community!

In bitbucket pipelines, when you are using pull-request triggers pipelines it should always merge the tip of the destination branch with the current working branch (the source of the pull request). So in this case, to get the commit hash that is shown in the merge command at Build Setup stage you could use git log as below : 

git log -n 1 --pretty=format:"%H" $BITBUCKET_PR_DESTINATION_BRANCH

This will print the tip of the destination branch of the pull request, which should match the commit hash presented in Build Setup.

As for getting the files that were changed in the source branch of the pull request, I think you could make use of the git three-way diff, as below : 

git diff $BITBUCKET_PR_DESTINATION_BRANCH...HEAD

This will list all the files that were changed in the source branch of the Pull Request starting at the last common commit between the source and destination branch of the pull request.

Hope that helps! Let me know in case you have any questions.

Thank you, @Felix .

Kind regards,

Patrik S

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events