Hello,
I am trying to use a second ssh key in my build pipeline which is using git ls-remote to pull nodejs classes from Repo B to Repo A (the build repo).
I am getting this error:
“Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.”
I referred to these questions for answers and nothing worked for me:
I also referred to this tutorial in the documentation :
https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/ (Section: Use multiple SSH keys in your pipeline)
to SUM up what I did so far:
Please find attached my pipeline file:
Thank you!
Hi @[deleted],
Checking your yml file, I see that you are not cloning any repo in the script, but you mention that this command fails:
- docker build -t $CR_ACR_HOSTNAME/$ACR_REPOSITORY_NAME:$BITBUCKET_COMMIT -t $CR_ACR_HOSTNAME/$ACR_REPOSITORY_NAME:$BITBUCKET_BUILD_NUMBER .
I assume that you have a Dockerfile in your repo that you are building, and you have a command to clone a repo in the Dockerfile?
If so, you will need to pass the SSH key to the docker build command and the known_hosts file also needs to be created in the Dockerfile.
I share below the steps that worked for me:
1. I created a secured variable named SSH_KEY in the repo where I build the Dockerfile.
The value of this variable is the private SSH key after I encoded it to base64.
The public key was added to the repo I want to clone.
2. In my bitbucket-pipelines.yml I build the Dokcerfile with the following command:
- docker build -t account/repo . --build-arg ssh_docker_key="${SSH_KEY}"
3. My Dockerfile includes the following lines:
ARG ssh_docker_key
RUN mkdir /root/.ssh/
RUN echo "$ssh_docker_key" | base64 --decode > /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/id_rsa
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan bitbucket.org > /root/.ssh/known_hosts
RUN git clone git@bitbucket.org:some-workspace/some-repo.git /home/app
Is this something that works for you?
Kind regards,
Theodora
Hello Theodora,
Yes your solution did the job for me. Thanks a lot!
Best Regards, Mohamed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mohamed,
That's good to hear and you are very welcome.
Please feel free to reach out if you ever need anything else!
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.