Skip to content
Advertisement

Using Multiple Operating Systems with Ruby and Shell in a Matrix with Travis CI

I’m attempting to create a CI test that executes a test using multiple Ruby versions using rvm on Linux, but I want to execute another test on Windows using the bash shell.

I’ve tried a few configurations, but they do not allow me to create or use multiple ruby versions if I have an additional OS and language in the matrix.

As an example, if I use the following configuration, I’ll get 3 different line items for Linux with different Ruby versions:

os:
  - linux

dist: xenial
language: ruby
cache: bundler

rvm:
  - 2.4.5
  - 2.5.4
  - 2.6.2

script:
  - ruby -v

Ruby RVM Travis CI

If I add a matrix and include different OS’s and languages, I just get 2 line items in the matrix — one for Linux (ruby) and one for Windows (shell). The Windows OS works fine, but Linux only executes the first ruby version in the rvm list.

matrix:
  include:
    - os: linux
      dist: xenial
      language: ruby
      cache: bundler
      rvm: 
        - 2.4.5
        - 2.5.4
        - 2.6.2
      script:
        - ruby -v
    - os: windows
      language: shell
      script:
        - powershell -Command Write-Host Test

Ruby/Windows Travis CI

I’d like to have 3 build jobs with different ruby versions listed for Linux, but just one shell build job on Windows. Is it possible to use rvm within a matrix with multiple OS’s and languages with Travis CI?

Advertisement

Answer

You have to define one include block for every build job:

matrix:
  include:
    - os: linux
      dist: xenial
      language: ruby
      cache: bundler
      rvm: 2.4.5
      script:
        - ruby -v
    - os: linux
      dist: xenial
      language: ruby
      cache: bundler
      rvm: 2.5.4
      script:
        - ruby -v
    - os: linux
      dist: xenial
      language: ruby
      cache: bundler
      rvm: 2.6.2
      script:
        - ruby -v
    - os: windows
      language: shell
      script:
        - powershell -Command Write-Host Test
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement