Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix job support #7

Closed
samrocketman opened this issue Nov 24, 2014 · 7 comments
Closed

Matrix job support #7

samrocketman opened this issue Nov 24, 2014 · 7 comments

Comments

@samrocketman
Copy link
Owner

Jervis needs to create matrix jobs from more complicated .jervis.yml files which test multiple things.

@samrocketman
Copy link
Owner Author

A Matrix job wiki page has been created for planning this.

A possible way to test env variables from .jervis.yml is to use a bash case statement. Let's say we have the following in our .jervis.yml file.

env:
  global:
    - FOOBAR=foobar
  matrix:
    - FOO=foo BAR=bar
    - FOO=bar BAR=foo

In the Jenkins job there would be a matrix variable (e.g. RANDMATRIXVAR_123) and it would have integer indices for each matrix it should execute (e.g. RANDMATRIXVAR_123="0 1"). Then our generated Jenkins code would look somewhat akin to the following.

#global variables for all matrices
export foobar=foobar
#variables per matrix index
case ${RANDMATRIXVAR_123} in
  0)
    export foo=foo bar=bar
    ;;
  1)
    export foo=bar bar=foo
    ;;
esac

The indices for the case should match the actual groovy array indices from the parsed yaml to simplify matrix filtering. In fact, now that I think of it this method can be used for all matrix build setup; yay! 💃

@samrocketman
Copy link
Owner Author

Jenkins supports matrix exclusion and inclusion in a one line expression.

!(rvm == "2.0.0" && gemfile == "Gemfile") && (rvm == "2.0.0")

Will exclude builds that exactly match rvm: 2.0.0 and gemfile: Gemfile but will include only combinations that have rvm: 2.0.0. Apply that matrix inclusion/exclusion string to the following yaml configuration.

language: ruby
rvm:
  - 1.9.2
  - 2.0.0
gemfile:
  - Gemfile
  - gemfiles/rails4.gemfile
  - gemfiles/rails32.gemfile
  - gemfiles/rails31.gemfile

That means only three matrix builds will actually execute. The matrix will build rvm: 2.0.0 against the gemfile: gemfiles/rails4.gemfile, gemfile: gemfiles/rails32.gemfile, and gemfile: gemfiles/rails31.gemfile.

The above one line expression can be more generically expressed as...

!(exclusion) && (inclusion)

@samrocketman
Copy link
Owner Author

Let's combine the previous two comments in a solid ruby example.

language: ruby
rvm:
  - 1.9.2 #$rvm index 0
  - 2.0.0 #$rvm index 1
gemfile:
  - Gemfile #$gemfile index 0
  - gemfiles/rails4.gemfile #$gemfile index 1
  - gemfiles/rails32.gemfile #$gemfile index 2
  - gemfiles/rails31.gemfile #$gemfile index 3
matrix:
  exclude:
    - { rvm: 2.0.0, gemfile: Gemfile }
  include:
    - rvm: 2.0.0

Will turn into bash code. Assume that the matrix environment variables are ${rvm} and ${gemfile} respectively.

case ${rvm} in
  0)
    rvm use 1.9.2
    ;;
  1)
    rvm use 2.0.0
    ;;
esac
case ${gemfile}
  0)
    export BUNDLE_GEMFILE="Gemfile"
    ;;
  1)
    export BUNDLE_GEMFILE="gemfiles/rails4.gemfile"
    ;;
  2)
    export BUNDLE_GEMFILE="gemfiles/rails32.gemfile"
    ;;
  3)
    export BUNDLE_GEMFILE="gemfiles/rails31.gemfile"
    ;;
esac

There will be two user-defined axes.

  1. Name: rvm; Value: 0 1
  2. Name: gemfile; Value: 0 1 2 3

The matrix filter would then look like the following (based on inclusion and exclusion filters).

!((rvm == "1" && gemfile = "0")) && (rvm == "1")

The following matrix will execute: $rvm == "1" and ($gemfile == 1 or $gemfile == 2 or $gemfile == 3).

@samrocketman
Copy link
Owner Author

I submitted a matrix plugin feature request to allow build failures in the matrix. This is so I can replicate Travis CI allow_failures configuration option.

@samrocketman samrocketman modified the milestone: 0.1.0 Dec 23, 2014
@samrocketman
Copy link
Owner Author

Partial support was implemented in 4bd3291.

Still need to support:

env:
  global:
    - FOOBAR=foobar
  matrix:
    - FOO=foo BAR=bar
    - FOO=bar BAR=foo

@samrocketman
Copy link
Owner Author

Matrix exclusion has been implemented in e4edfa8.

@samrocketman
Copy link
Owner Author

Matrix support has been fully implemented today leading up to commit 591f6bb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant