Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IF / ELSE statement inside .yml file

Tags:

travis-ci

Is there a way to use IF/ELSE inside the .yml file?

I wanted to define env variables if it's not a pull request.

Something like this idea:

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?

like image 802
Sergio Avatar asked Mar 14 '14 07:03

Sergio


1 Answers

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

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

[ "${TRAVIS_PULL_REQUEST}" != "false" ] && BROWSER='chrome_linux' BUILD='default' || true
like image 164
banzaiman Avatar answered Nov 07 '22 12:11

banzaiman