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

Samples or commands for modifying bitbucket branch permissions using powershell or git commands

Daniel ThamizhSelvam P November 29, 2017

Samples or commands for modifying bitbucket branch permissions using powershell or git commands.

We do not have Bit bucket CLI rather, hence suggest a good approach model to execute the above scenario.

2 answers

0 votes
Julius Davies _bit-booster_com_
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.
December 8, 2017

I've done it with bash and the free token authenticator add-on.  Here's a sample script for setting the "no changes" permission (with Group1 and Group2 exempt from it) against the current "development" branch (based on the branching model):

#!/bin/bash

export TOKEN='Fr1bRsIEPq[...]AmM='

read -r -d '' JSON <<'EOF'
{"type":"read-only", "matcher":{"id":"development", "type":{"id":"MODEL_BRANCH"}, "active":true}, "users":[], "groups":["Group1","Group2"]}
EOF

echo $JSON |
curl -s -H "X-Auth-User:gsylvie" \
-H "X-Auth-Token:$TOKEN" \
-H "Content-Type: application/json" \
--data @- -X POST \
https://vm.bit-booster.com/bitbucket/rest/branch-permissions/2.0/projects/PROJECT/repos/repo/restrictions

 

Deleting branch permissions is a bit trickier.  I had to resort to installing the jq command from github to extract the ID of the restriction to delete:

export ID=$(\
echo $JSON | \
jq '.values[] | select(.type=="read-only" and .matcher.id=="development") | .id' \
)

 

If you're trying to propagate a standard set of branch permissions out to all your repositories then I recommend using my paid add-on:  Control Freak for Bitbucket Server.

 

0 votes
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 8, 2017

Hi Daniel! Git itself does not have branch permissions. You could create one private repository and one public repository and only push the development branch to the public on while keeping the master only in your private repository.

For branch specific permissions you need a server-side authorization layer like Gitolite for example (note that this requires you to be managing your own Git server). You can find more info at Git on the Server Gitolite.

Alternatively, you can use Bitbucket to manage branch permissions. You can learn more in the article Using branch permissions.

Hope that helps!

Ana

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events