Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull from private repo in a bitbucket pipeline?

I have a bitbucket pipeline that works well but now on a project i need to pull from a private repository wich contains a package that is required in my composer.json.

When i do a composer install in the pipeline, it stops with this error

Failed to execute git clone --no-checkout '[email protected]:company/package.git' [...]
  Cloning into '/opt/atlassian/pipelines/agent/build/vendor/company/package'...                                                                                                                                                                                                                                                                                 
  Permission denied (publickey).                                                                                                                                                                                                                                                                                                                                                
  fatal: Could not read from remote repository.                                                                                                                                                                                                                                                                                                                                 
  Please make sure you have the correct access rights                                                                                                                                                                                                                                                                                                                           
  and the repository exists. 

The pipeline do not have any SSH key defined so it's not allowed to pull, but how could i define one since it's ephemeral ?

Or maybe i should define the requirement otherwise ?

like image 635
user3005099 Avatar asked Apr 17 '17 14:04

user3005099


People also ask

How do I access private Bitbucket repository?

A private Git repository on Bitbucket can be accessed using either SSH or HTTPS. The preferred method is to always use SSH and a SSH key pair. Only use HTTPS if you have no choice.

How do I pull something out of Bitbucket?

Then, open the Bitbucket website on your browser and navigate to the repository in question. Click on the menu button in the top-left, and select Pull Requests. Here, click on the Create pull request button. The pull request creation form will open.


1 Answers

  • Add a deployment key (public SSH key) to the private repository
  • Add that key’s corresponding private key (Base64-encoded) as environment variable in the repo that has the Pipeline. Ideally, this should be marked as protected, which will hide it.
  • Use the environment variable (Base64-decoded) in the Pipeline. Ususally, that means something like writing it to the user’s .ssh directory.

That should be enough to get it running.

Moreover, I’ve just seen that there is now (maybe this is new, but I’m not sure) a new page “Settings” > “Pipelines” > “SSH keys” for managing pipelines SSH keys. This way, you wouldn’t even need to add the private key to the docker image you are using. But I haven’t used that so far, so I can’t say anything about it.

like image 142
BlueM Avatar answered Nov 15 '22 02:11

BlueM