Amit
Amit

Reputation: 6284

Travis-CI deploy every master commit, but not branch commits

I have set up travis to test my project, and to deploy a docker build for every commit.

What I really want to do, is to test every commit I have, and only when it is being rebased to master, deploy it (it's for my staging environment, in which I always want master up and running)

Is there a way I can separate these tasks, so instead of having the deployment on every commit, it will only happen when a commit is rebased to master?

Note, that rebasing to master does not create a new commit, so I am not sure if it will even trigger travis.

The following is my .travis.yml:

sudo: required # is required to use docker service in travis

language: node_js

node_js:
  - 'node'

services:
  - docker

before_install:
  - npm install -g yarn --cache-min 999999999
  - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16"

# Use yarn for faster installs
install:
  - yarn

# Init GUI
before_script:
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"
  - sleep 3 # give xvfb some time to start

script:
  - npm run test:single-run

cache:
  yarn: true
  directories:
     - ./node_modules

after_success:
  - npm run build:backwards # Build production AOT build
  - docker --version  # Document the version travis is using
  - pip install --user awscli # install aws cli w/o sudo
  - export PATH=$PATH:$HOME/.local/bin # put aws in the path
  #- eval $(aws ecr get-login --region us-west-2) # needs AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY envvars
  #- docker build -t ansyn/client-chrome.v.44 .
  #- docker tag ansyn/client-chrome.v.44:latest 223455578796.dkr.ecr.us-west-2.amazonaws.com/ansyn/client-chrome.v.44:latest
  #- docker push 223455578796.dkr.ecr.us-west-2.amazonaws.com/ansyn/client-chrome.v.44:latest
  - echo "deployment succeded"

Upvotes: 0

Views: 874

Answers (1)

feildmaster
feildmaster

Reputation: 114

Looks like you need to run a deploy script.

You would do this in .travis.yml

deploy:
  provider: script
  script: bash scripts/deploy.sh
  on:
    branch: master

And scripts/deploy.sh would contain what you currently have in after_success.

Upvotes: 2

Related Questions