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

Deploy to remote staging server using Bitbucket

EVO_9 March 27, 2018

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 votes
Linette
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2018

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!!

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 2, 2018

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

EVO_9 April 3, 2018

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?

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 3, 2018

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
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 8, 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
TAGS
AUG Leaders

Atlassian Community Events