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?
4.5 years after: still a valid question to Atlasian. Google led me to this page.
The APIs like
http://myhost.com:8085/bamboo/rest/api/latest/plan/{projectKey}-{buildKey}/branch
or http://myhost.com:8085/bamboo/rest/api/latest/plan/{projectKey}/{buildKey}
do not return which branch is the default one.
That is a problem, because if you use the following API to get the build results
http://myhost.com:8085/bamboo/rest/api/latest/result/{projectKey}-{buildKey}/branch/{branchName}
and the branch you search IS the default one (assume it is named "default"), you get an error:
{"message":"Branch default not found.","status-code":404}
Basically, the API works for non-default branches only. Which would not be a problem, if we were able to find out the name of the default branch, and if confirmed to match, use the following API instead:
http://myhost.com:8085/bamboo/rest/api/latest/result/{projectKey}-{buildKey}
But for that I need to be able to get the default branch name somehow.
Wasting a lot of time trying to find a way to determine the name of the default branch via API. This is stupid.
EDIT: anyway, found a way to do it. Use following endpoint:
https://{bamboo_server}/rest/api/latest/search/branches.json?masterPlanKey={projectKey-planKey}&includeMasterBranch=true
result with "type": "chain" will be the default branch.
or for a specific branch:
https://{bamboo_server}/rest/api/latest/search/branches.json?masterPlanKey={projectKey-planKey}&includeMasterBranch=true&branchNameOnly=true&searchTerm={branchName}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Help from Atlasian? Is there a way to query the build status of the default branch via the REST API?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.