A Cloud Architect Company
bitbucket pipeline
DevOps

How to Clone another repository data for Bitbucket Pipeline

Bitbucket Pipeline is a continuous integration and continuous deployment (CI/CD) service, It helps you to automatically build, test and even deploy your code based on a configuration file in your repository.

In this blog , we are going to explore how to clone a Bitbucket repository in Bitbucket pipeline in simple way, just follow the below commands

Generate SSH key in pipeline repository

SSH keys are pair of public and private keys that are used to authenticate and establish an encrypted communication between a client and a remote machine over the internet.

Open your pipeline Bitbucket repository → click Repository settings

Clone a Bitbucket repository using Bitbucket Pipeline repository settings

 

Also Learn:  How bitbucket pipeline triggers only when changes made in a particular folder

 

Scroll down and click SSH keys under pipelines section

Clone a Bitbucket repository using Bitbucket Pipeline ssh key

Now you can see a popup message like “pipelines must be enabled

Clone a Bitbucket repository using Bitbucket Pipeline setting(pipeline)

Click “go to settings” you will see the enable option like below screenshot and then enable the pipeline

Clone a Bitbucket repository using Bitbucket Pipeline enable setting(pipeline)

Now we have successfully enabled the pipeline !

Clone a Bitbucket repository using Bitbucket Pipeline enabled

Now scroll down and click the same SSH keys option under the pipelines section → click Generate keys

Clone a Bitbucket repository using Bitbucket Pipeline generate keys

Now it will automatically generate private & public key , then copy the public key for future reference, we want to add this public key in our source repository

Clone a Bitbucket repository using Bitbucket Pipeline public key

Now open your source repository(which will contain your codes/files) → Repository settings → click Access keys under security section

Clone a Bitbucket repository using Bitbucket Pipeline access key

Now click Add key

Clone a Bitbucket repository using Bitbucket Pipeline add key

Now Enter the label name → paste our public key under key section → click Add SSH key

Clone a Bitbucket repository using Bitbucket Pipeline public key added

We have successfully added our Bitbucket pipeline repository SSH public key to our source repository

Create pipeline

Now again open your pipeline repository → click pipelines → and then click create your first pipeline

Clone a Bitbucket repository using Bitbucket Pipeline first pipeline

 

You will redirected to the content like below screen shot then click select on Started pipeline

Clone a Bitbucket repository using Bitbucket Pipeline select

Now you will redirected to a bitbucket-pipelines.yml file

Clone a Bitbucket repository using Bitbucket Pipeline edit file

Just remove entire content below “image: atlassian/default-image:3” line ,

Open your source repository and click clone option

Clone a Bitbucket repository using Bitbucket Pipeline clone

 

By default it will be in HTTPS option, but now we are going to use SSH option , so change the option from HTTPS to SSH by clicking the dropdown list icon

Clone a Bitbucket repository using Bitbucket Pipeline https

Switching to SSH and then copy the git clone URL , we will use this URL in next step, inside bitbucket-pipelines.yml file

Clone a Bitbucket repository using Bitbucket Pipeline ssh

Now replace the 5th line with your source repository SSH URL , which was already copied in previous step

pipelines:
  default:
    - step:
        script:
          - git clone [email protected]:baskey/source_repo.git
          - ls

Copy the above script and then paste it in pipeline repository ,under the “image: atlassian/default-image:3” line , inside the bitbucket-pipelines.yml file , like below screenshot and click commit file

It will help us to clone another repository in our pipeline and by using “ls” we can view the cloned files

Clone a Bitbucket repository using Bitbucket Pipeline update

 

Now you will see the success status within few seconds

Clone a Bitbucket repository using Bitbucket Pipeline success

Just click the successful status, you will redirected to appropriate page and then by clicking each command you can see the list of process have done by the pipeline setup like below screen shot

Clone a Bitbucket repository using Bitbucket Pipeline review

Article written by:

Junior DevOPs Engineer, working @ Easydeploy Technologies Pvt Ltd, Coimbatore, with 1 year of experience, and currently Doing server configurations by automation using Ansible & building strong AWS resources using Terraform, and creating a containerized application using Docker.

Leave a Reply

Your email address will not be published. Required fields are marked *

back to top
advanced-floating-content-close-btn

Contact Us to save your AWS bill by 40%

X