Missed Team ’24? Catch up on announcements here.

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

Bamboo REST API to create branches

Arthur Maltson September 23, 2013

Maybe I missed it, but is there a Bamboo API to create branches? There seems to be ones to GET branches, but I'd like to create new branches. The Bamboo polling mechanism works, but polling is much slower than a push mechanism.

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 23, 2013

Hello Arthur,

I believe there is an undocumented API for creating arbitrary branch-plan since Bamboo 5.0. Usage gist:

curl -X PUT --user admin:admin http://localhost:8085/rest/api/latest/plan/PROJ-PLAN/branch/yourNewBranchName?vcsBranch="/refs/heads/myBranch"

(the "yourNewBranchName" is the name of the plan-branch visible in Bamboo UI, and the "vcsBranch" parameter defines which branch should be used when polling your source code repository)

Does this help you?

regards,

Arthur Maltson September 23, 2013

That's exactly what I wanted, thank you!

Now I'm wondering, is there a way to modify the task that branches run vs master? For example, we use Maven and our master build does a mvn clean deploy, whereas the branch I'd like to do a mvn clean verify (not deploy). Perhaps this is worth a separate question.

PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

@Nicholas: I believe both answers are "no".

Do you have access to the Bamboo sources?

Nicholas Parrish October 2, 2013

This is perfect. Is this documented anywhere? Can you modify the description as part of the same request? I've tried

http://.../PLAN/branch/branch_name?vcsBranch=branch_name&description=blah

Steven Wagner January 30, 2014

Are any of the other parameters that can be modified in the branch editor GUI modifiable via the REST API?

Or does this all require Bamboo source access?

(Does every on-site Bamboo license holder have source access? If so, I gotta make some calls around the office... )

Steve Muskiewicz February 11, 2014

We're a Bamboo OnDemand customer.

I tried to use the undocumented API (using the exact curl statement shown in the example) but got a "411 - Length required" response. Any workarounds for this? It would be great to be able to automate branch creation in our Bamboo plans.

Thanks!

[edit] Answering my own question:

Sounds like it is specific to nginx (which is what Atlassian uses for gw to OnDemand), see http://serverfault.com/questions/164220/is-there-a-way-to-avoid-nginx-411-content-length-required-errors

Workaround is to add -H "Content-Length: 0" to your curl command. I did this and it worked great!

Matthew Douston January 3, 2019

I know I'm late to the party in asking this, but is there a way to use this REST API to enable the branch plan and set its trigger type to manual?

I can use the shared REST API syntax to create a branch plan, but I'd like to also make sure I can enable the plan and change its trigger type to manual with this same call, if possible. Some background on this: I have dozens and dozens of develop branches that I have to manually create plan branches for, which are set up with a manual trigger type to work with Bob Swift automation. I'd like to automate creating all those release branch plans.

GlennT June 14, 2019

did you manage to find a solution for this?

0 votes
Erik Husby June 17, 2014

Was away so have not responded.

Yes, I have the vcsBranch option in the REST call.

My problem turned out to be a BASH scripting error - Since I was using Basic authentication, my url looked like

curl --verbose -X PUT --user xxx:pwd http://host:8085/rest/api/latest/plan/E2P-SB/branch/release-1.1?os_authType=basic&vcsBranch=/refs/heads/release/1.1

And the &vcsBranch was being treated as a background job. It needed to be escaped with a "\"

So now I am one step closer, now I get Bamboo complaining that the branch can not be found:

Eriks Test Project - Sandbox - Branch - release-1.1 › E2P-SB1-1 : Errors getting changes for E2P-SB1-1
(com.atlassian.bamboo.repository.RepositoryException : java.lang.RuntimeException: com.atlassian.bamboo.repository.InvalidRepositoryException: Cannot determine head revision of 'ssh://git@stash.broadinstitute.org:7999/et/sandbox.git' on branch '/refs/heads/release/1.1'. Branch has probably been removed.)
(17 Jun 2014, 4:42:40 PM)

In the branch's Source Repository tab, the branch name was listed as /refs/heads/release/1.1.

I then checked out Branch plans that were automatically created and saw that their branches names were simply "release/1.1"

So, in summary, for GIT, the correct value for the vcsBranch parameter should not include /ref/heads, but the simple branch name.

I would have saved a lot of time, if the REST documentation was fleshed out.

0 votes
Erik Husby June 2, 2014

When I try this with a GIT repo, it does create a new branch plan but it does not overide the repository setting so it does not use the branch for the build.

There is "some" documentation for the 5.5 API -- but it does not say much.

https://docs.atlassian.com/bamboo/REST/5.5.0/#d2e645

Any one really doing this who can share their techniques?

PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 2, 2014

Hi Erik,

Just to be sure we're standing on the same ground: have you used the vcsBranch parameter in your REST calls? I mean the

?vcsBranch="/refs/heads/myBranch"

part in your PUT request?

Michael Vinca October 13, 2015

For SVN, I just use ?vcsBranch=myBranch It might be similar for GIT. If I put quotes or /branches/ then my URL is messed up for my branch. The plan is already setup to look for branches in .../branches as opposed to .../trunk so it only needs the part after .../branches/

0 votes
EddieW
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 23, 2013

Not sure what repo you are using, but for SVN it is a fixed 5 minute interval

https://answers.atlassian.com/questions/80492/how-can-i-force-bamboo-to-re-scan-the-automatic-branch-detection-for-svn

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events