How to clone other BitBucket repo during build?

I know this is possible because I’ve done it earlier with another CircleCI project, but I cannot make it work now and keep going in circles.

The error I get is:

#!/bin/bash -eo pipefail
git clone git@bitbucket.org:AAA
Cloning into 'content'...
Unauthorized
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Exited with code exit status 128
CircleCI received exit code 128

From what I understand, I need to configure something in the project’s ‘SSH Keys’ settings. Even though my other CircleCI project that accesses BitBucket private repositories doesn’t have special settings there.

On that ‘SSH Keys’ page, I get confused. There’s a hyperlink that says “See the Bitbucket integration docs.”. However, that link points to https://circleci.com/docs/github-integration/#creating-a-bitbucket-user-key, and on that page BitBucket is mentioned never. The heading linked to doesn’t exist there either.

Via online search I found this page: https://circleci.com/docs/bitbucket-integration/#enable-your-project-to-check-out-additional-private-repositories. There it says " Scroll down the page to User Key and click Authorize with Bitbucket .". However, my ‘SSH Keys’ page doesn’t have an ‘Authorize with Bitbucket’ button.

If I try the ‘Add User Key’ button on the ‘SSH Keys’ page, which I do have, then the build still fails and I get this error:

Using SSH Config Dir '/home/circleci/.ssh'
git version 2.38.1
Cloning git repository
Cloning into '.'...
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

exit status 128

Would anyone know the process I should take to make this work? Thanks so much for any suggestions! :slightly_smiling_face:

The starting point is this section

Most of the documentation is regarding the process of allowing Circleci access to the repo so that it can correctly execute the checkout step that needs read-only access to the repo. If you plan to use git within your own scripts you have to start installing ssh keys onto the host yourself - the docs show this, but they do seem to expect you to already know why you are doing this as no real explanation is provided.

1 Like

Thanks for the reply! And for the docs link.

In writing my reply to you I was thinking about the fingerprints YAML key that my successful project uses, rather than a add_ssh_keys step.

And when I searched for more information about fingerprints, I found this support page that solved my problem.

Now my build successfully fetches from BitBucket!

Thanks for your help and moral support. :slightly_smiling_face:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.