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 @easybiblabs solved the same problem slightly different by wrapping it in a
TO_TEST
envvar with multiple values, which helps if you are running multiple commands after each other per build, or have to use different setup statements in the install section. It roughly works along those lines: