Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to use ssh keys to push to bitbucket repository in bitbucket pipelines

David Essien
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 26, 2022

I am trying to clone a repository, update values in a file, and then commit and push while inside a bitbucket pipeline.

 

I followed the example in this repository provided by bitbucket to use ssh keys to push to another bitbucket repository.


https://bitbucket.org/bitbucketpipelines/git-auth-ssh-using-variables/src/master/bitbucket-pipelines.yml

```

pipelines:
default:
- step:
script:
# Configure git to use ssh.
- git remote set-url origin ${BITBUCKET_GIT_SSH_ORIGIN}
- echo $PRIVATE_KEY > ~/.ssh/id_rsa.tmp
- base64 -d ~/.ssh/id_rsa.tmp > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
# Commit back.
- echo "Made a change in build ${BITBUCKET_BUILD_NUMBER}" >> changes.txt
- git add changes.txt
- git commit -m "[skip ci] Updating changes.txt with latest build number."
- git push

```

- I added my private ssh keys as a secure variable

- and I tried to create file for my ssh key to use as a private key, but in the bitbucket pipeline, it echos the variable itself and not the value into the file.

My guess is that the above behaviour is because I added it as a secure variable. Please is there a work around for this?

We have several repositories that will need to clone this one repository, it is not scalable to all all their pipeline ssh keys into that one repository.

 

2 answers

0 votes
Hiren Patel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 26, 2024

I am facing same issue,, 

0 votes
Norbert Csupka
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 28, 2022

Hi David,

Thank you for contacting Atlassian Community, I'm Norbert from Bitbucket Cloud Support team, it's nice to meet with you!

I would like to inform you that this is an expected behavior as we don't show the secured variable, but the file actually should contain the private key. When I tested this, I did an "cat ~/.ssh/id_rsa" command and I could see the content of the file.

Can I ask you to run a "cat ~/.ssh/id_rsa" command in your Pipelines, after the "base64 -d ~/.ssh/id_rsa.tmp > ~/.ssh/id_rsa" command and let me know if you can see any content in the file?

I'm looking forward to hear from you.

Best Regards,
Norbert
Atlassian Bitbucket Cloud Support

Daniel Lopez
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 23, 2022

Norbet C, I have the same problem! I ran cat ~/.ssh/id_rsa, and I dint show me anything; the private key was empty. 

Norbert Csupka
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 25, 2022

Hi @Daniel Lopez 

Thank you for commenting on this ticket.

Can you let me know if you were creating the "id_rsa.pub" file the same way as David did?

echo $PRIVATE_KEY > ~/.ssh/id_rsa.tmp
base64 -d ~/.ssh/id_rsa.tmp > ~/.ssh/id_rsa

 I'm looking forward to hear from you.

Best Regards,
Norbert
Atlassian Bitbucket Cloud Support

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events