Search code examples
bitbucketcicdbitbucket-pipelinesdroplet

Bitbucket auto deploy to Linux server (DigitalOcean Droplet)


I have encountered a problem while attempting to deploy my code to a Droplet server (running Ubuntu) using BitBucket Pipeline.

I have set the necessary environment variables (SSH_PRIVATE_KEY, SSH_USER, SSH_HOST) and added the public key of the SSH_PRIVATE_KEY to the ~/.ssh/authorized_keys file on the server. When I manually deploy from the server, there are no issues with cloning or pulling. However, during the automatic CI deployment stage, I am encountering the error shown in the attached image.

enter image description here

This is my .yml configuration.

enter image description here

Thanks for helps in advance.


Solution

  • To refer to the values of the variables in defined in the configuration, you script should use $VARIABLE_NAME, not VARIABLE_NAME as that is literally that string.

    - pipe: atlassian/ssh-run:latest
      variables:
        SSH_KEY: $SSH_KEY
        SSH_USER: $SSH_USER
        SERVER: $SSH_HOST
        COMMAND: "/app/deploy_dev01.sh"
    

    Also, note some pitfalls exists when using an explicit $SSH_KEY, it is generally easier and safer to use the default key provided by Bitbucket, see Load key "/root/.ssh/pipelines_id": invalid format