Can a non background step wait until the preceding backgrounds steps are completed?

I have a config.yml looks like:

version: 2.0
jobs:
  build:
    environment:
      DBUS_SESSION_BUS_ADDRESS: /dev/null
      TZ: "Europe/Berlin"
      BUNDLE_PATH: vendor/bundle
    docker:
      - image: circleci/ruby:2.3-node-browsers
        environment:
          DATABASE_HOST: 127.0.0.1
          DATABASE_USER: ubuntu
          DATABASE_PASSWORD: ""
          # https://docs.npmjs.com/getting-started/fixing-npm-permissions
          NPM_CONFIG_PREFIX: ~/.npm-global
      - image: circleci/postgres:9.6-alpine-postgis
        environment:
          POSTGRES_USER: ubuntu
    steps:
      - checkout
      # .. some other steps
      - run:
          name: Start Webpack server
          working_directory: frontend
          background: true
          command: sysconfcpus -n 1 npm start
      - run:
          name: Start Rails server
          working_directory: backend/ruby
          background: true
          command: RAILS_ENV=development bin/rails s -p 3000 -b 0.0.0.0
      - run:
          name: Install E2E gems
          working_directory: frontend_end_to_end
          environment:
            BUNDLE_JOBS: 4
            BUNDLE_RETRY: 3
          command: |
            wget --waitretry=5 --retry-connrefused -v http://127.0.0.1:8080/
            bundle check || bundle install
            bundle exec rspec ./spec

Can I use up the when option to tell the step Install E2E gems to start when the preceding 2 steps succeeded?

Yes. Write a file at the end of your background tasks, and then finally use a Bash loop to detect when all the files have been written.

The file writing could be as easy as:

sysconfcpus -n 1 npm start && touch /tmp/finished1

(and the same for the others, but use finished2, finished3, etc.)

Thanks for your idea. When to use when option then?

If you mean the 2.1 feature of conditional steps, you don’t need that here. I guess that would be useful if, for example, you wanted to run optional test/build steps based on the contents of a Git tag.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.