Deploy to remote staging server using Bitbucket

Hi

Very new to Git and Bitbucket and I am trying to deploy my site to my remote server.

Here is my Pipeline code, which I have copied so not even sure it works at the moment.

 

# Check our guides at https://confluence.atlassian.com/x/e8YWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: samueldebruyn/debian-git

pipelines:
default:
- step:
script:
- mkdir -p ~/.ssh
- umask 077 - echo $MY_SSH_KEY | base64 --decode > ~/.ssh/id_rsa

- scp -i ~/.ssh/id_rsa -P $SERVER_PORT -r $DIRECTORY_TRANSFER_LIST $USERNAME@$SERVER_IP_ADDRESS:~/test

 

I have setup Environment Variables for SERVER_PORT which is 22, USERNAME to match my login username, SERVER_IP_ADDRESS to my remote server's IP.

What I don't understand is: 

MY_SSH_KEY

and

DIRECTORY_TRANSFER_LIST?

And where it finds my SSH Key?

(I have already set up an SSH that connects to my computer in the main Bitbucket Settings and that seems to push my files to the repo ok)

And should the image be: 

image: samueldebruyn/debian-git

I got this from following a youtube video for setting Bitbucket up with FTP

1 answer

0 vote

Hi Daniel!

First of all, welcome! Git and Bitbucket can seem confusing at first, but don't worry, it gets easier. It seems like there are a few questions here, so I'll try and point you in the right direction.

So, the first thing I notice about your pipelines config there is that the indentation is messed up. Maybe that's just because of pasting it into the community here, but if not I thought I should mention that. The file is very sensitive to spacing (you can't even use tabs!). You might find this get started page useful for examples.

From the code you've posted you'll also need to define MY_SSH_KEY as a secure environmental variable. You can get a bit more detail on environmental variables here (and secure ones are explained in more detail at the bottom).

This question and it's answer might be some help to you too. It goes through setting up SSH in pipelines so you can use ssh, sftp, or scp with your pipeline.

Best of luck and welcome to Pipelines!!

Just adding that we've got a simpler process for using SSH keys now. Try looking at the documentation here, as it might be easier for you to set everything up!

https://confluence.atlassian.com/bitbucket/use-ssh-keys-in-bitbucket-pipelines-847452940.html

So I've been playing about with this for ages now, my current code is:

image: docksal/bitbucket-pipelines-agent

pipelines:
  custom: # Pipelines that are triggered manually
    test:
      - step:
          script:
            - mkdir -p ~/ssh
            - cat known_hosts >> ~/ssh/known_hosts
- umask 077 - echo $MY_SSH_KEY | base64 --decode > ~/.ssh/id_rsa
- scp -i ~/.ssh/id_rsa -P $SERVER_PORT -r $DIRECTORY_TRANSFER_LIST $USERNAME@$SERVER_IP_ADDRESS:~/path/to/project

 

But I get an error

 + cat known_hosts >> ~/ssh/known_hostscat: can't open 'known_hosts': No such file or directory

What is going on?

All the guides I find use this known_hosts line bt it's not working?

Hey Daniel,

Can you try start fresh with these instructions. https://confluence.atlassian.com/bitbucket/use-ssh-keys-in-bitbucket-pipelines-847452940.html

Manually setting known_hosts and SSH keys as part of your pipeline build is quite a pain to get right. We've got some features above that should hopefully make that a bit easier for you to set up.

Kanwar Plaha Atlassian Team Apr 08, 2018

Hi Daniel,

In the script provided on the page, the directory should be .ssh and not just ssh. Please see below to confirm:

- mkdir -p ~/.ssh
           - cat my_known_hosts >> ~/.ssh/known_hosts

Let us know if this helps.

Regards,

Kanwar

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

23,890 views 26 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you