If/else statement in my travis yaml configuration

we are on enterprise and wondering if something like this was possible:

env:
  matrix:
    if ($TRAVIS_PULL_REQUEST) {
      - BROWSER='chrome_linux'    BUILD='default'
      - BROWSER='chrome_linux'    BUILD='nocompat'
      - BROWSER='firefox_linux'    BUILD='default'
      - BROWSER='firefox_linux'   BUILD='nocompat'
   }
   else {
     - BROWSER='phantomjs'    BUILD='default'
   }

is this possible?

I don’t think this particular use case would work. TRAVIS_PULL_REQUEST is defined on the build worker, while build matrix must be constructed before Travis hands off the job to the worker.

I suggest writing a wrapper, so basically a script that takes TRAVIS_PULL_REQUEST and sets the environment variables correctly, or do something like this in before_install:

[ "${TRAVIS_PULL_REQUEST}" != "false" ] && BROWSER='chrome_linux' BUILD='default' || true
1 Like