Files are persisted to workspace, but then not restored

One job does:

- persist_to_workspace:
    root: .
    paths:
      - '*'

With “Persisting to workspace” output:

Creating workspace archive…

Uploading workspace archive…
Total size uploaded: 62 MiB
Workspace archive uploaded successfully.

A later job does:

- attach_workspace: { at: . }
- run:
   name: "Foo"
   command: "something_to_generate_a_dist_folder"
- persist_to_workspace:
    root: .
    paths:
      - dist

With “Persisting to workspace” output:

Creating workspace archive…

Uploading workspace archive…
Total size uploaded: 2.6 MiB
Workspace archive uploaded successfully.

A later job does:

- attach_workspace: { at: . }

with “Attaching workspace” output

Downloading workspace layers
workflows/workspaces/6963932b-…/0/b9b35173-…/0/108.tar.gz - 65 MB
Total size downloaded: 62 MiB
Applying workspace layers
b9b35173-ae18-4ac3-986b-e47bfbeed5ea
935315fa-ab7c-4b2c-aa21-842b4ac3ecdb - persisted no files

It tries to access “dist”, but there’s no such folder. Why?

1 Like

Have you found a way to resolve this? I’m experiencing a similar issue (where I successfully persist a file, but then the file is not uploaded by attach workspace so I get file not found issues).

Afraid not. I bailed on this optimisation and have not revisited.

Try using the root as the same path used for your working_directory attribute, and I recommend using relative paths, that way it worked for me.

Something along these lines

jobs:
  npm_install:
    working_directory: ~/app
    description: "Install and cache npm packages"
    steps:
      - checkout
      - persist_to_workspace:
          root: ~/app
          paths:
            - ./*

Ran into a similar issue and I resolved it by ensuring there is a link between the source and the destination job. That is, making the source job a pre-requisite for the destination job.