Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,020
Community Members
 
Community Events
176
Community Groups

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

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.

 

1 answer

0 votes
Norbert C Atlassian Team Jan 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

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 C Atlassian Team Feb 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

Atlassian Community Events