B
B
Bogdan2019-04-30 12:24:20
Travis CI
Bogdan, 2019-04-30 12:24:20

Deploy depending on the branch?

Hello. Tell me please. I now have a ssh deployment configured in Travis from the Master branch, everything works fine. But now there was a need to first deploy to the server for tests, for example, when committing to the Development branch, what would be deployed to one server, when committing to the Master branch to another server.
For example, I have such a file now.
.travis.yml

language: node_js

env:
  SSH_USER: root
  DEPLOY_PATH: /root/coffee/coffee
  SERVICE_NAME: coffee

sudo: false

node_js:
  - node

git:
  depth: false

branches:
  only:
    - master

cache:
  directories:
    - node_modules

before_install:
  - openssl aes-256-cbc -K $encrypted_<key>_key -iv $encrypted_<key>_iv -in ./.travis/id_rsa.enc -out ./.travis/id_rsa -d
  - eval "$(ssh-agent -s)"
  - chmod 600 ./.travis/id_rsa
  - echo -e "Host $SSH_HOST\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
  - ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts
  - ssh-add ./.travis/id_rsa

install:
  - npm install

script:
  - echo "npm test temporarily disabled"
  - npm run build

deploy:
  provider: script
  skip_cleanup: true
  script: bash -c '
    rsync --recursive --quiet --delete-after dist/* [email protected]$SSH_HOST:$DEPLOY_PATH
    && ssh [email protected]$SSH_HOST "systemctl restart $SERVICE_NAME"'
  on:
    branch: master

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question