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

How can I use SSH in Bitbucket Pipelines to update files in server?

Scorpyons August 21, 2017

Hi Guys!

I'm struggling to make pipeline to work. I just want Bitbucket simply update the changes to my server.

 

I already installed git in my server. I can ony access my server via ssh. I also already included my Host address in SSH Keys, and Fingerprint is already being displayed.

 

Here is my current yml configuration:

# 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:
          - apt-get update
          - apt-get -qq install git-ftp
          - git ftp init --user $FTP_USERNAME --passwd $FTP_PASSWORD ftp://123.45.678.901/site.com/

Are the informations correct? What I'm missing?

I just want to update my server once I commit and push the files to bitbucket.

Can you guys help me?

1 answer

0 votes
Shane Fast September 12, 2017

I haven't tried it the way your are yet, but I have had success using scp:

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:~/path/to/project
 

Where $DIRECTORY_TRANSFER_LIST is the name of the project directory you wish to transfer

Scorpyons September 14, 2017

Hi @Shane Fast

Thanks for your response. When I access my server, I have the following folders: Maildir , sitename.com and logs.

So based on your example, I should use:

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

Is this correct?

Also should I use id_rsa or this is something that I also have to change?

Shane Fast October 4, 2017

Yes, based on the info you provided that appears to be the correct command.

as for id_rsa - its just the standard name for the key file. You can name it whatever you want as long as its the same name as the command preceeding it:

- umask 077 - echo $MY_SSH_KEY | base64 --decode > ~/.ssh/<name of file holding my private key>

- scp -i ~/.ssh/<name of file holding my private key> -P .....

Saving it into the .ssh directory and using umask 077 are required for setting the correct permissions on the key file. Without the correct permissions on the key file any remote commands or transfers will be rejected for built in security reasons.

Scorpyons October 12, 2017

Hi @Shane Fast

Thanks for your response once again.

Sorry for my many questions, I'm really a beginner on this. 

Regarding this line: echo $MY_SSH_KEY 

Should I include the SSH public key (a really big number), or should I use this variable ($MY_SSH_KEY) as it is?

EVO_9 March 27, 2018

Any update on this, i'm stuck?

 

I'm getting: bash: scp: command not found

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events