2

I've created a Bitbucket repository using a Jenkinsfile, with the following code (with private data replaced with {}):

sh "curl -X POST -H \"Authorization: Basic {KEY}=\"
\"https://api.bitbucket.org/2.0/repositories/{project}/{repository_name}\" 
-H \"Content-Type: application/json\"  
-d '{\"has_wiki\": true, \"is_private\": true, \"project\": {\"key\": \"{key}\"}}'"

This creates a repository with default access rights.

I need to then give a Group Write access to this repository.

I've scoured the internet and I can't find any up to date documentation or examples of how to do this. How do I do this using a shell command?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
James
  • 749
  • 1
  • 9
  • 22

1 Answers1

3

What you are looking for is: "permission":"write"

Here are the API calls to update the group permissions:

"permission":"write"

The full API call:

curl --request PUT --user username:password \ 
<repo url> \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data '{"name":"developers","permission":"write","auto_add":true}'
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • What format should the be? I seem to get a no such file or directory error no matter what I put. Also, further to this, how would I do this without having to put a raw username and password into the request? Is a BASIC authorisation token possible to use instead? – James Nov 19 '18 at 09:18
  • 1
    Your bitbucket URL for the given repository – CodeWizard Nov 19 '18 at 09:51
  • I managed to get the shell command to complete, however it doesn't seem to have changed anything on the repository. I'll have a look around to see if I can find out why. Thank you for your help so far! – James Nov 19 '18 at 09:59
  • The documentation I've found online suggests the following format for the URL:https://api.bitbucket.org/1.0/groups/username@example.com/designers/. Is this the format you are expecting? This to me looks like the format for updating a group privilege within a group, not for adding a group to a repository. The raw URL of my repository (https://bitbucket.org//) command works but does not result in the group being added to the repo. – James Nov 19 '18 at 10:28