Which workspace is used when jobs are run concurrently?

I have the following simplified .circle/config.yml file:

version: 2
jobs:
  install-dependencies:
    docker:
      - image: circleci/node:10.15.3
    steps:
      - checkout
      - run:
          name: Install Dependencies
          command: yarn install --frozen-lockfile
      - persist_to_workspace:
          root: ./
          paths:
            - ./
  # Build jobs
  build-staging:
    docker:
      - image: circleci/node:10.15.3
    steps:
      - attach_workspace:
          at: ./
      - run: yarn run build:staging
      - persist_to_workspace:
          root: ./
          paths:
            - dist
  build-production:
    docker:
      - image: circleci/node:10.15.3
    steps:
      - attach_workspace:
          at: ./
      - run: yarn run build:prod
      - persist_to_workspace:
          root: ./
          paths:
            - dist
  # deploy jobs
  deploy-staging:
    docker:
      - image: circleci/python:3.7.2
    steps:
      - attach_workspace:
          at: ./
      - run: some-deploy-command
  deploy-production:
    docker:
      - image: circleci/python:3.7.2
    steps:
      - attach_workspace:
          at: ./
      - run: some-deploy-command
workflows:
  version: 2
  build:
    jobs:
      - install-dependencies
      # build
      - build-staging:
          requires:
            - install-dependencies
      - build-production:
          requires:
            - install-dependencies
      # deploy
      - deploy-staging:
          requires:
            - build-staging
      - deploy-production:
          requires:
            - build-production

Basically the workflow ordering is:

  1. install-dependencies
  2. build-staging & build-production is run concurrently after install-dependencies. I assume attach_workspace gets the data from install-dependencies job. Am I correct?
  3. deploy-staging is run after build-staging . deploy-production is run after build-production . I am not sure what work-space is attached when running attach_workspace .

As you can see, multiple jobs can run concurrently. However, my issue is that I am confused as to how persist_to_workspace and attach_workspace works when it is not clear in what order a certain task finishes. Unlike caching, it does not seem to be possible to name what data I want.

For example, lets say the jobs finish in the following order:

  1. install-dependencies
  2. build-staging
  3. build-production
  4. deploy-staging
  5. deploy-production

What workspace do I get at step 3 and step 4. Is it always the one preceding it (in this case it would be step 2 & 3), or is it based on the parent task (i.e. step 1)?

Hi Yahya, I believe it’s the last one that was persist_to_workspace unless the steps are so close together that it hasn’t finished saving, in which case it should be one prior.

1 Like

Thanks a lot.

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