Skip a travis.yml deploy for opened pull requests?

1k Views Asked by At

I have a Travis repo enabled for pull requests. When a pull request is opened, the travis.yml triggers both the tests and the deploy script.

I would like opened pull requests to run all tests, but not run the deploy script unless merged.

Below is a sample of my travis.yml:

sudo: true
language: node_js
before_deploy:
  - wget https://s3.amazonaws.com/go-cli/releases/v6.12.4/cf-cli_amd64.deb -qO temp.deb && sudo dpkg -i temp.deb
  - rm temp.deb
  - cf login
  - cf install-plugin autopilot -r CF-Community
  - npm run build
deploy:
- edge: true
  provider: script
  script: cf zero-downtime-push app-name -f ./manifest.yml
  on:
    branch: master
1

There are 1 best solutions below

1
On BEST ANSWER

You can use travis special environment variable TRAVIS_PULL_REQUEST to detect if build is triggered for PR.

So your script can look like:

...

deploy:
- edge: true
  provider: script
  script: if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then cf zero-downtime-push app-name -f ./manifest.yml; else echo "PR skip deploy"; fi
  on:
    branch: master

More travis varibles you can faund on:
https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables