Access yarn cache from another job

I’ve been looking around but I can’t seem to find anything that can help my use case. I just need to have the node_modules available on the client_build job.

version: 2
jobs:
  set_up_deps:
    docker:
      - image: circleci/node:10
    steps:
      - checkout
      - run:
          name: update-npm
          command: 'sudo npm i -g npm@6.9.0'
      - run:
          name: install-yarn
          command: 'sudo npm i -g yarn'
      - restore_cache:
          keys:
            - yarn-packages-{{ checksum "yarn.lock" }}
      - run:
          name: install-deps
          command: yarn install --frozen-lockfile
      - save_cache:
          key: yarn-packages-{{ checksum "yarn.lock" }}
          paths:
            - ~/.cache/yarn
  client_build:
    docker:
      - image: circleci/node:10
    steps:
      - checkout
      - restore_cache:
          keys:
            - yarn-packages-{{ checksum "yarn.lock" }}
      - run:
          name: build-client
          command: yarn client:build:prod
workflows:
  version: 2
  build:
    jobs:
      - set_up_deps
      - client_build:
          requires:
            - set_up_deps

Heya @iamdevlinph, this is typically a case where workspaces are necessary :slight_smile: Give it a shot and see how it goes. It behaves a little differently from caching, and tends to work very well in this scenario.

I found workspaces before but it seemed too complicated for a simple use case that’s why I just brushed it aside. I’ll give it another look.