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 ???
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.