Bitbucket Pipeline - Pull/Push code using SSH Key without Permission denied

Luong Truong January 17, 2021

Hello guys, to be honest, I am struggling with the Bitbucket Pipeline

Below is my question with Bitbucket Pipeline

Scenario:

- I have 2 repos: Library and Package. Library contains the source code and the Package contains specific code that would be re-used in many projects.

- Bitbucket Pipeline is enable for both Library and Package repo.

- I write the code in Library repo, build, and push the final code to Package repo. Therefore, Library and Package repos need to communicate using Bitbucket Pipeline.

Question:

- How can I use SSH Key in Bitbucket Pipeline to pull/push code from Library repo to Package repo without the permission denied?

- According to this link: the third comment from Maze Hawks, adding the SSH Key to Personal Setting allow to do it, but do we have any alternative ways so we don't have to add the SSH Key to Personal Setting?

If you have any ideas, please feel free to give the answers or comments. I am really appreciated.

1 answer

1 accepted

0 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 18, 2021

Hi @Luong Truong and welcome to the community!


- How can I use SSH Key in Bitbucket Pipeline to pull/push code from Library repo to Package repo without the permission denied?

If you want to use SSH, you can generate an SSH key pair from Repository settings > SSH keys in the Library repo, then, copy the public key.

Afterwards, go to your Personal settings > SSH keys and add the public key there.

If you have at least write access to Package repo, you'll be able to push this way from Pipelines of the Library repo.

- According to this link: the third comment from Maze Hawks, adding the SSH Key to Personal Setting allow to do it, but do we have any alternative ways so we don't have to add the SSH Key to Personal Setting?

Another way is to use HTTPS. You can generate an app password for your account that has at least write access to repositories:

Then to go Library Repository settings > Repository variables

Create two variables, named e.g. BitbucketUsername and BitbucketPassword (please make sure that BitbucketPassword is created as a secured variable, so no one else can see it)

Afterwards, you can use an HTTPS URL like the following to push:

https://$BitbucketUsername:$BitbucketPassword@bitbucket.org/<workspace-id>/<repo-slug>.git

There is another option, which is to use OAuth for authentication. This is explained in detail here:

Please note that the example there assumes that you are pushing back to the same repo where Pipelines runs.

Since you want to push to a different repo, you can change the variable ${BITBUCKET_REPO_SLUG} in the URL with the repo slug of the repo you are pushing to.

Does any of these options work for you?

Please feel free to let me know if you have any questions.

Kind regards,
Theodora

Luong Truong January 21, 2021

Hello @Theodora Boudale , thank you for your super clear answer. I am really appreciated.

Like Theodora Boudale likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events