{{announcement.body}}
{{announcement.title}}

Cloning Another Bitbucket Repository in Bitbucket Pipelines

DZone 's Guide to

Cloning Another Bitbucket Repository in Bitbucket Pipelines

In this article, take a look at cloning a bitbucket repository in bitbucket pipelines.

· DevOps Zone ·
Free Resource

I recently had a use case where I wanted to clone another Bitbucket repository during a Pipelines execution. Doing this is very simple, but there is a lot of conflicting information online, so I thought I would document the steps here.

Imagine a very simple Pipeline that looks like this:

YAML


The repository that triggers the Pipeline will need permission to clone my-submodules.

Create SSH Keys for the Main Repository

In Bitbucket, go to the repository SSH keys page under Settings > Pipelines > SSH keys.

Cloning another Bitbucket repository in Bitbucket Pipelines - Settings > Pipelines > SSH keys


Next, click on Generate keys to let Bitbucket auto-generate a random, secure SSH key-pair. You can also upload a custom key-pair if you want.

You may also like: How I Use Bitbucket In My Regular Routine

Cloning another Bitbucket repository in Bitbucket Pipelines - Generate keys

 

Once completed, click Copy public key. We will need to paste this in the next step.

Add SSH Public Key in the Target Repository

Go to the my-submodules repository. Under Settings > General > Access keys, you should see the option to add SSH public keys to gain read-only access.

 

Cloning another Bitbucket repository in Bitbucket Pipelines - Settings > General > Access keys

 

Click Add key, enter a label, and paste the public key we copied in the previous step.

 

Cloning another Bitbucket repository in Bitbucket Pipelines - Add key

 

Our main repository now has read-only permissions to clone my-submodules from within its Pipelines. After the above configuration, executing a build for the repository will show all green.

 

Cloning another Bitbucket repository in Bitbucket Pipelines - Successful deployment!


Further Reading

Publishing API Console on Bitbucket Pages

Source Control Using Atlassian Bitbucket

Topics:
bitbucket pipelines ,ci/cd ,devops ,tutorial

Published at DZone with permission of Ayush Sharma , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}