Multiple OS Build Help

Quick caveat, I’m brand new to Travis-CI, and don’t have much YAML experience. I’ve picked up an open source project that already has a linux build, and I’m trying to add a windows build set to it as well.

This config is not getting me what I want… e.g. the if statements down on the node_js section don’t seem to be having any effect, I don’t want to target some node_js versions for windows. I’m still researching this a bit, but thought the community might shine some quick answers.

language: node_js

os:
    - linux
    - windows
    
sudo: required

addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - libudev-dev

before_install:
  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then wget https://github.com/OpenZWave/open-zwave/archive/master.zip    ; fi
  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then unzip master.zip                                                   ; fi
  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then cd open-zwave-master                                               ; fi
  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo make install                                                  ; fi
  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo ldconfig /usr/local/lib /usr/local/lib64                      ; fi
  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then npm install -g node-gyp                                            ; fi
  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then cd ..                                                              ; fi

node_js:
  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then "0.12" ; fi
  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then "4" ; fi
  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then "6" ; fi
  - "8"
  - "10"
  - "11"
  - "12"

Thanks in advance.

You can’t assign node_js values with bash if statements. They have to be pre-determined.

What you want is something like:

node_js:
  - "8"
  - "10"
  - "11"
  - "12"
matrix:
  include:
    - os: linux
      node_js: "0.12"
    - os: linux
      node_js: "4"
    - os: linux
      node_js: "6"

Also, stylistically, I’d suggest rolling all of those if statements in the before_install into a single statement:

before_install:
  - |
    if [ ]; then
      wget …
      unzip …
    ⋮
    fi

This makes sense, I wasn’t even thinking about those if statements being bash instead of a yaml construct… totally makes sense… I’ll give your suggestions a go.

Works perfectly. Thanks for the support @BanzaiMan.

language: node_js

os:
    - linux
    - windows
    
sudo: required

addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - libudev-dev

before_install:
  - |
    if [ "$TRAVIS_OS_NAME" = "linux" ]
    then 
        wget https://github.com/OpenZWave/open-zwave/archive/master.zip
        unzip master.zip
        cd open-zwave-master
        sudo make install
        sudo ldconfig /usr/local/lib /usr/local/lib64
        npm install -g node-gyp
        cd ..
    fi

node_js:
  - "8"
  - "10"
  - "11"
  - "12"
  
matrix:
  include:
    - os: linux
      node_js: "0.12"
    - os: linux
      node_js: "4"
    - os: linux
      node_js: "6"
Imprint