Access the GitHub repository from the bitbucket pipelines cicd

If you are like me and part of your company is using Bitbucket while the other part is using GitHub -> you might find this post helpful. If you need to git pull a repository from GitHub into one of your bitbucket pipeline steps – read on.

Add ssh key into the bitbucket pipeline:

Go into your bitbucket pipelines settings and add an ssh key. Either click and generate a new one or use an existing one if you have one:

Bitbucket pipelines add ssh keys

Note: you don’t need to add to known hosts. It’s already added under the hood by default in Bitbucket.

Add public ssh key into GitHub repository

Copy the public ssh key you added in the previous step into the GitHub repository you want to pull into your bitbucket pipeline.

You can add the ssh key under the settings => deploy keys:

Example bitbucket-pipelines.yml that git pull(s) GitHub repository:

After the above prep work is complete, you can pull the GitHub repository like this for example in your bitbucket pipeline. Here im using the python alpine image, but code would be similar in any other image:

    - &integration-test
      name: Api integration test
      image: python:3.11-alpine
        enabled: false
        # Install git and ssh
        - apk update && apk add git openssh-client

        # git clone the repo from github: 
        - git clone --verbose
        - CLONE_DIR=`pwd`/mezzio-nginx-swoole-demo

        # Do what you please
        - cd ${CLONE_DIR} && ls -alh


  # Pipelines that can only be triggered manually
      - step: *integration-test

Thank you for reading 👍

Leave a Comment