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

How can I push to a new repository from within bitbucket pipelines

mateusz_maly_external March 21, 2023

Hi,

I have a pipeline setup in which I create a brand new bitbucket repository and push some templates to it. Now I can get read access through the use of project and repository SSH keys. But I need to push code to the new repo so that does not work. How can I allow this one repo to have write access to other repositories within the workspace or projects?

This is a brand new repo I'm creating every time so ideally some workspace level access would be best. 

 

Thanks

2 answers

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 22, 2023

Hi @mateusz_maly_external and welcome to the community!

I just wanted to add that there is one more option, other than the ones that Riley suggested: you could also use SSH.

  1. Open on Bitbucket Cloud website the page of the repo where you run these builds.
  2. Select Repository settings from the sidebar on the left
  3. Select SSH keys from the new sidebar on the left
  4. On this page, generate an SSH key pair
  5. Copy the public SSH key that is generated, and add it to the workspace's SSH keys (from the workspace's settings > SSH keys)

This way, your build will have write access to all the repos that belong to this workspace.

If you want to push to a newly created repo from your build this way, you will then need to use the SSH URL of this newly created repo. The format is as follows:

git@bitbucket.org:workspace-id/repo-slug.git

If you have any questions, please feel free to reach out!

Kind regards,
Theodora

0 votes
Riley Venable
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 21, 2023
To allow this new repository to have write access to other repositories within the workspace, you can use a Bitbucket Cloud Workspace Access Token with the following permissions: Repository Read (repository) and Repository Write (repository:write). You can create a Workspace Access Token with these permissions and include it in the URL, or provide it through an interactive prompt when using the Git CLI. You can also use OAuth by creating an account or bot account, giving that account write access in the branch permission to allow pushing directly to your main branch. Follow the steps listed above to create an OAuth consumer, record the keys, and add them as pipeline variables with the names CLIENT_ID and CLIENT_SECRET. Then, add the necessary script section to your bitbucket-pipelines.yml file.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events