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

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 vote

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

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.

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

23,881 views 26 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you