Task is to trigger gitlab pipeline when commit to other branches except develop and master, also while merge to master branch only.
Below code pipeline runs for all commits and merges
stages:
- backup
- pull
- build
- deploy before_script:
Run ssh-agent (inside the build environment) eval $(ssh-agent -s) ssh-add <(echo “$DEV_WEB_KEY”) chmod 600 ~/.ssh continuous_backup_to_dev: stage: backup rules:
- if: $CI_COMMIT_BRANCH != “master”
- if: $CI_COMMIT_BRANCH != “develop”
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == “master” tags:
- devbe script:
ssh -t -t root@$DEV_WEB_IP -o StrictHostKeyChecking=no "cd /root && rm -rf Webapp_old && cp -r Webapp Webapp_old && exit " continuous_pull_to_dev: stage: pull rules:
- if: $CI_COMMIT_BRANCH != “master”
- if: $CI_COMMIT_BRANCH != “develop”
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == “master” tags:
- devbe script:
- ssh -t -t root@$DEV_WEB_IP -o StrictHostKeyChecking=no “cd /root/Webapp && git pull && exit” continuous_build_to_dev: stage: build rules:
- if: $CI_COMMIT_BRANCH != “master”
- if: $CI_COMMIT_BRANCH != “develop”
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == “master” tags:
- devbe script:
- ssh -t -t root@$DEV_WEB_IP -o StrictHostKeyChecking=no “cd /root/Webapp && npm install && exit” continuous_deploy_to_dev: stage: deploy rules:
- if: $CI_COMMIT_BRANCH != “master”
- if: $CI_COMMIT_BRANCH != “develop”
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == “master” tags:
- devbe script:
- ssh -t -t root@$DEV_WEB_IP -o StrictHostKeyChecking=no “cd /root/Webapp && pm2 restart Webapp && bash pm2statusmail.sh && exit”