Setting up parallel execution with multiline yml

The guides always mention a single line test command execution and how to make it parallel

- bundle exec rspec:
  parallel: true

What if my test command is quite long and I’m using the > operator to make it multiline ?

- >
    RAILS_ENV=test bundle exec rake "knapsack:cucumber[
      -t @critical
      --format json 
      --out $CIRCLE_TEST_REPORTS/cucumber/tests.cucumber
    ]"
1 Like

I use like that:

test:
  override:
    - bash -c "$CMD":
        parallel: true
        environment:
          CMD: >
            case $CIRCLE_NODE_INDEX in
              0) yarn run lint ;;
              1) yarn run flow ;;
            esac

But I’m not sure that best way(

1 Like

Another way to do this is:

test:
  override:
    - ? |
        if [[ $CIRCLE_BRANCH != "test-branch" ]] ;
          then
            case $CIRCLE_NODE_INDEX in
            0) run-my-tests.sh ;;
            1) run-my-tests-2.sh ;;
          esac ;
        fi
      :
          parallel: true

Multiline strings are “complex” yaml objects, so to use them as keys in a map, you need to use the ? key : format.

Note that parallel: true is indented by 4 spaces from the preceding :

(Thanks to Eric on the support team for suggesting this approach to me)

4 Likes