Terraform IaC Tool | Multibranch Pipeline with Git
Access Another Bitbucket Repository From a Bitbucket Pipelines
Fix the “ERR! Unauthorized, fatal: Could not read from remote repository” error
You may have encountered this error before. It commonly occurs when attempting to clone a Bitbucket repository from another Bitbucket repository pipeline. Here are a few steps you can follow to resolve this error.
Let’s say you want to clone the mycomponents
repository from themyapp
repository pipeline. Themyapp
repository that triggers the pipeline will need permission to clonemycomponents
.
Create a repository
Clone over SSH
git clone git@bitbucket.org:<workspace-or-project-name>/<repository-name>.git
Clone over HTTPS
git clone https://<username>@bitbucket.org/<workspace-or-project-name>/<repository-name>.git
example: git clone git@bitbucket.org:my-project/mycomponents.git
1. Create an SSH key
First, you need to create an SSH key in the myapp
repository.
- In Bitbucket, go to the repository SSH keys page.
Repository Settings > Pipelines > SSH keys
.
- Click on the
Generate keys
button below to auto-generate a random, secure SSH key pair. You can also upload a custom key pair if you prefer.
Once Bitbucket auto-generates a random secure SSH key pair, as you see below, click on theCopy public key
button to copy the public key.
2. Add SSH public key
Now you need to add the created SSH key to the mycomponent
repository
- Go to the
mycomponent
repository, select Repository Settings, andGeneral > Access keys.
click on theAdd key
button to add the public key.
- You will get a popup to add the SSH key, give a label name for the key, and paste the previously copied public key into the
key
section.
Ta-da 🥳, now yourmyapp
repository has read-only permissions to clone the mycomponents
repository.
"ERR! Unauthorized, fatal: Could not read from remote repository " error is no more.
References :
https://support.atlassian.com/bitbucket-cloud/docs/using-ssh-keys-in-bitbucket-pipelines/