How to identify the default branch for a given build key?

Gregory Paciga February 28, 2020

I'm working on a CI system that uses the current git branch to look up a build key and start a build in Bamboo.

So far, I'm using the /plan/{projectKey}-{buildKey}/branch endpoint to get all the branches and their keys to look up the key for the branch I'm trying to build. The problem is that the default branch doesn't appear in this list.

For example, if I have project key PK and build key BK, I call /plan/PK-BK/branch and get something like this back (leaving out a bunch of keys):

{
"branches": {
"branch": [{
"shortName": "my-feature-branch",
"key": "PK-BK123"
}, {
"shortName": "second-feature-branch",
"key": "PK-BK234"
}]
}

If my CI server is trying to build my-feature-branch or second-feature-branch, this works fine.

But there's nothing I can find that maps the default branch name - the one I see if I just navigate to /browse/PK-BK in the UI - to the PK-BK build key. Nor have I found anything that goes the other way: knowing that PK-BK is the default, look up what branch name that is. I can't hard code the branch name ("if the current branch is develop, use the root build key") because I want this to work in multiple repos that might have different default branches.

Is there something in the API that can give me this info, or is there a better strategy entirely for mapping from git branch to build key?

1 answer

0 votes
Alex Lynch September 12, 2022

Help from Atlasian? Is there a way to query the build status of the default branch via the REST API? 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events