I have a project that's been happily chugging along on Travis for a while. Its .travis.yml
looks something like
script:
- node_modules/ember-cli/bin/ember test
I wanted to add a second parallel build that did something very different. I didn't want to run ember test
with a different Ember version or some other flag. I wanted to run a completely different command. Specifically, I wanted to run LicenseFinder's audit.
Travis has great docs on customizing parallel builds, but nothing describes how to do two completely different commands.
I poked at Bash for a while and finally came up with
env:
- TEST_COMMAND="node_modules/ember-cli/bin/ember test"
- TEST_COMMAND="bundle exec license_finder"
script:
- (eval "$TEST_COMMAND")
The eval
inherits the current shell's environment, and the (...)
wrapping creates a sub-shell to isolate this shell from the effects of TEST_COMMAND
.
This was my first attempt. I still don't quite understand why it doesn't work.
script:
- $TEST_COMMAND
A second go breaks because I didn't wrap the argument to bash -c
in quotes, meaning any arguments I tried to pass to ember
got lost:
script:
- bash -c $TEST_COMMAND
But even wrapping it in quotes failed because bash -c
loses too much of the environment:
script:
- bash -c "$TEST_COMMAND"
We at @phpbb we have a problem similar (we need different setup and test suite depending on the environment) and we solved it like @fh.
In the matrix we define a few envvar and we use them to select and configure our scripts.
This way we can do whatever we want and run exactly what we want in each configuration.
https://github.com/phpbb/phpbb/blob/3.1.x/.travis.yml