Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to use SSH key to deploy angular production build to an external server using bitbucket pipeline

Suren March 18, 2019

We are trying to use Bitbucket Pipelines to deploy a basic angular application to a VM on Google Cloud but are not sure how to use SSH key to connect to the server to copy the build files. Looking for examples but could not find.

We were able to do the same manually using Putty/SSH commands to copy the dist files.

We have the public/private key from Google Cloud's VM, and added them to Bitbucket Pipelines > SSH Keys

Our YML script is as below:

image: node:6.9.4

pipelines:
  default:
    - step:
       caches:
         - node
       script: # Modify the commands below to build your repository.
         - npm install
         - npm install -g @angular/cli@1.6.4
         - ng build --prod
         - cd dist/
         - ssh -i ???

 

1 answer

1 accepted

0 votes
Answer accepted
Suren March 19, 2019

We were able to solve this as below:

1. Under Bitbucket > Project source repository > Settings > Pipelines > SSH Keys

1.1 Add private and public keys and

1.2 Add Known hosts (this will the IP address of the server you want to push the code to. In our case this is a VM on Google Cloud)

2. Update your script as below:

# Sample build file
# @author Suren Konathala
image: node:8
pipelines:
default:
- step:
caches:
- node
script: # Modify the commands below to build your repository.
#- echo "$(ls -la)"
- npm install
- npm install -g @angular/cli
- ng build --prod
- echo "$(ls -la dist/)"
- scp -r dist/ suren@34.73.227.137:/home/suren/temp

 Observe: You can use scp command to push code to external server

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events