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

Add a new group to all existing repos in an org?

Dominic Vallejo February 21, 2018

Hi, I want to create a new read only group that id like to add to all of our existing repos without having to add them one at a time.

Is this possible?

2 answers

1 accepted

0 votes
Answer accepted
Steven Whitman February 22, 2018

There isn't anything out of the box that I'm aware of but you could do this with either ScriptRunner to the Bitbucket REST API.  

Use this REST API to add a group to a project:

PUT: /rest/api/1.0/projects/{projectKey}/permissions/groups?permission={permission}&name={group}

Replace {projectKey} with the project's key.

Replace {permission} with PROJECT_READ, PROJECT_WRITE or PROJECT_ADMIN

Replace {group} with the name of an existing group.

Use this REST API to add a group to a repository in a project:

PUT: /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/permissions/groups?permission={permission}&name={group}

Replace {projectKey} with the project's key.

Replace {repositorySlug} with the repositories slug (typically the name of the repo with spaces replaced by hyphens).  The two rest APIs I mention below can be used to get the slugs.

Replace {permission} with REPO_READ, REPO_WRITE or REPO_ADMIN

Replace {group} with the name of an existing group.

To get the first 1000 projects on the server use:

GET: /rest/api/1.0/projects?limit=1000

And to get the first 1000 repos in the project use this:

GET: /rest/api/1.0/projects/{projectKey}/repos?limit=1000

Replace {projectKey} with the project's key which was obtained with the GET REST call above.

Muniraja SREERAM October 8, 2019

@Steven Whitman , It is help us if you share the new API's to add the groups to Bitbucket repositories? those API's not working what you mentioned in the solution 

We are using Bitbucket cloud.

Steven Whitman October 10, 2019

Sorry I don't have access to Bitbucket cloud, you'd need to ask someone else what are the equivalent APIs for the cloud product.

0 votes
Muniraja SREERAM October 8, 2019

Bitbucket Cloud REST API version 1 is deprecated 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events