trigger:
- master
pool:
vmImage: ubuntu-latest
variables:
- group: "sshKeyPassphrase"
- name: "frontendDir"
value: "frontend"
- name: "backendDir"
value: "backend"
- name: "remoteServer"
value: "ssh.the360expo.com"
- name: "remoteUser"
value: "u413-vckbx5xu4xp8"
- name: "remotePath"
value: "/home/u413-vckbx5xu4xp8/www/virtualconsultation.the360expo.com/public_html"
- name: "remoteServerPath"
value: "/home/u413-vckbx5xu4xp8/www/virtualconsultation.the360expo.com/vpc_server"
- name: "sshKeySecureFileName"
value: "vpc-corn-job-pri.pub"
steps:
- task: NodeTool@0
inputs:
versionSpec: "14.x"
displayName: "Install Node.js"
- task: DownloadSecureFile@1
name: sshKey
displayName: "Download SSH Key"
inputs:
secureFile: "vpc-corn-job-pri.pub"
- script: |
cd $(frontendDir)
cp .env.prod .env
npm install
npm run build
displayName: "npm install and build"
- script: |
echo "Secure File Path: $(sshKey.secureFilePath)"
chmod 600 $(sshKey.secureFilePath) # Fix permissions
eval $(ssh-agent -s) # Start the SSH agent
mkdir -p ~/.ssh # Ensure the .ssh directory exists
touch ~/.ssh/known_hosts # Ensure the known_hosts file exists
ssh-keyscan -p 18765 $(remoteServer) >> ~/.ssh/known_hosts # Add the remote server to the known hosts file
echo "$(corn_ssh_key_passphrase)" | ssh-add $(sshKey.secureFilePath) # Add the SSH key to the agent
sshpass -p "$(corn_ssh_key_passphrase)" scp -P 18765 -r $(frontendDir)/dist/* $(remoteUser)@$(remoteServer):$(remotePath) # Use sshpass to pass the passphrase and perform the SCP operation
displayName: "SCP Frontend dist folder to Remote Server"
env:
corn_ssh_key_passphrase: $(corn_ssh_key_passphrase)