How to deploy code to ec2 ubuntu using bitbucket pipelines?
below is the code for deploying code to ec2 ubuntu using gitlab cicd
stages:
- backupvm1 #backupfiles in webvm1
.before_script_stg_template:
before_script:
## Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
- echo "EC2_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "EC2_SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
rules:
- if: $CI_COMMIT_BRANCH == "master"
when: always
- when: never
continuous_backup_to_vm1:
stage: backupvm1
extends:
- .before_script_stg_template
script:
- ssh -t ubuntu@$EC2_IP -o StrictHostKeyChecking=no " rm -rf folder_bkp && cp -r folder folder_bkp&& exit"
rules:
- if: $CI_PIPELINE_STATUS != "failed"