Pull request identifiers in Bamboo

Now that support for pull requests has been added in Bamboo 6, I'm interested in closing the loop with a Bitbucket pull request by letting my Bamboo build post comments back into the PR. I'd like to use this to automate some aspects of code review using tools like Danger.

I've been able to successfully set up my Bamboo plan to be triggered when a pull request is created in Bitbucket. My next step is to post comments back into the PR using the Bitbucket API. I'll need at least three bits of info

  1. The repo's project key on Bitbucket
  2. The repo's slug on Bitbucket
  3. The pull request's identifier on Bitbucket

The project key and slug can be parsed out of info that is already available to the build. For example, the bamboo.planRepository.<position>.repositoryUrl variable

What I don't see is a way to get the pull request's identifier. Is there a variable or setting that I'm missing that makes this identifier available to the tasks during a Bamboo build?

I've looked at the other variables listed in Bamboo's documentation and also looked at the environment variables available during my task's execution using the printenv command in a Script task. 

1 answer

Maybe you already have found a solution to this, but I am facing the same issue.  I looked as well, and there does not seem to be any variable available 'out-of-the-box' in Bamboo.

One way I can see to get more information about the PR associated with the branch I am building is to use the 'pull-requests' endpoint of the Bitbucket REST API.  (send GET to rest/api/1.0/projects/<PROJ_NAME>/repos/<REPOSITORY_NAME>/pull-requests) -- then you can parse the 'values' returned to lookup the identifier for the branch you are interested in.

The branch information should be available in Bamboo's $repository.git.branch variable.

I really like your idea of posting a comment back to the PR with some useful info!

After searching for some more, this ticket seems to exactly describe the issue:  https://jira.atlassian.com/browse/BAM-18350

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

31,249 views 26 12
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you