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

How to configure branching model with REST API in Bitbucket Data Center?

Lucky June 6, 2024

Dear Community,

I want to configure my Bitbucket Data Center (Atlassian Bitbucket v8.9.12) repository Workflow > Branches configuration via REST API. 

Sadly, I could only find the REST API documentation for Bitbucket Cloud here The Bitbucket Cloud REST API (atlassian.com) to configure the branching model.

But it doesn't seem to be available in the Bitbucket Data Center version. Or at least I could not find it in the REST API documentation The Bitbucket Data Center REST API (atlassian.com).

Thanks for a hint.

Best Regards,

Daniel

1 answer

2 votes
Charlie Misonne
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 6, 2024

Hi Daniel and welcome to the Atlassian Community!

I was looking for this a while ago and I found the answer in this comment on a feature request.

There is an endpoint but is not official. It has been working for years though...

PUT <bitbucket-url>/rest/branch-utils/1.0/projects/{projectKey}/repos/{repositorySlug}/branchmodel/configuration

{
    "development":{
        "refId":"refs/heads/develop",
        "useDefault":false
    },
    "types":[
        {
            "id":"BUGFIX",
            "displayName":"Bugfix",
            "enabled":true,
            "prefix":"bugfix/"
        },
        {
            "id":"FEATURE",
            "displayName":"Feature",
            "enabled":true,
            "prefix":"feature/"
        },
        {
            "id":"HOTFIX",
            "displayName":"Hotfix",
            "enabled":false,
            "prefix":"hotfix/"
        },
        {
            "id":"RELEASE",
            "displayName":"Release",
            "enabled":true,
            "prefix":"release/"
        }
    ]
}

Use GET on the same endpoint to view the current branching model of the repo.

I hope this helps!

Lucky June 7, 2024

@Charlie Misonne Thanks for the helpful response. Do you maybe know if the other settings under branches Automatic merging, Automatic branch merging behavior and Branch deletion on merge are also configurable via the API?2024-06-07_15h18_38.png

 

Update: Found this for automatic merging [BSERV-4894] Display auto-merge status using REST API. - Create and track feature requests for Atlassian products. -> Solved

Still looking for branch-deletion-on-merge but should work via the same endpoint I guess --> But what's the key which must be used?

/rest/branch-utils/1.0/projects/{PROJECT_KEY}/repos/{REPO_SLUG}/<whats the key here?>/enabled

UPDATE 2: Found it here Bitbucket REST API to set 'Branch deletion on merge' - DevOps Stack Exchange

It's /rest/branch-utils/latest/projects/{project_key}/delete-after-merge and to set it to ON  sent a POST request with {"enabled": true}

Like Charlie Misonne likes this
Charlie Misonne
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 10, 2024

Hi!

You got everything you needed now? :-)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events