# Understanding persist\_to\_workspace

**URL:** <https://discuss.circleci.com/t/understanding-persist-to-workspace/31369>\
**Category:** Build Environment\
**Created:** [July 16, 2019, 7:26am UTC](https://discuss.circleci.com/t/understanding-persist-to-workspace/31369 "2019-07-16T07:26:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andybiotika](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@andybiotika](https://discuss.circleci.com/u/andybiotika)\
**Post date:** [July 16, 2019, 7:26am UTC](https://discuss.circleci.com/t/understanding-persist-to-workspace/31369/1 "2019-07-16T07:26:37Z")

</div>

Im struggling here and hope someone can help me out. I just dont get how the root and path attributes are working together with persist\_to\_workspace.

I do the following:

```
  - checkout
  - run: rm -rf .git
  - persist_to_workspace:
      root: /root
      paths:
        - project

```

Later I do:

```
attach_workspace:
   at: ~/

```

This works. In my first job I have the workspace at `/home/circleci/project` with my everything I need.  
Now I build my frontend which gives me a folder at `/home/circleci/project/frontend/build`.

The only thing I want to do now is persisting this folder at the same path so that its available in the next job who attachs the workspace at `~/project/frontend/build`. But however I do the persist\_to\_workspace the build folder always is at the same level of project.

```
ls
-> project frontend/build

```

instead of

```
ls
-> project/frontend/build

```

How can I do that?

---

<div class="post-metadata">

**Author:** ![andybiotika](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@andybiotika](https://discuss.circleci.com/u/andybiotika)\
**Post date:** [July 16, 2019, 7:36am UTC](https://discuss.circleci.com/t/understanding-persist-to-workspace/31369/2 "2019-07-16T07:36:12Z")

</div>

After wasting 2 hours yesterday…I had it 2mins after posting here…

I did this

```
  - persist_to_workspace:
      root: ~/
      paths: project/frontend/build

```

And it seems to save the workspace like I want to.

---

<div class="post-metadata">

**Author:** ![promisepreston](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/promisepreston/32/32790_2.png) [@promisepreston](https://discuss.circleci.com/u/promisepreston)\
**Post date:** [April 16, 2023, 12:24pm UTC](https://discuss.circleci.com/t/understanding-persist-to-workspace/31369/3 "2023-04-16T12:24:09Z")

</div>

Thanks for this. Had a similar issue for a project I was working for.

I needed to add a file through a job to the project during build. I did it this way.

I added the checkout in the **config job** , and disabled checkout in the **aws-ecr** and **aws-ecs** jobs:

```auto
version: 2.1
parameters:
  image_tag: #tag of the docker image to rollback to (app version)
    type: string
    default: "0"
  rollback_trigger: #was build trigger by a request to rollback app version
    type: boolean
    default: false
orbs:
  aws-ecr: circleci/aws-ecr@8.2.1
  aws-ecs: circleci/aws-ecs@03.2.0
workflows:
  build-and-deploy:
    jobs:
      # PULL REQUESTS
      - config:
          name: config-pr
          filters:
            branches:
              ignore:
                - development
                - main
                - staging
      - aws-ecr/build-and-push-image:
          attach-workspace: true
          aws-access-key-id: AWS_ACCESS_KEY_ID_DEV
          aws-cli-version: latest
          aws-secret-access-key: AWS_SECRET_ACCESS_KEY_DEV
          checkout: false
          create-repo: false
          dockerfile: Dockerfile
          name: build-pull-request
          path: .
          platform: linux/amd64
          public-registry: false
          push-image: false
          region: '${AWS_REGION}'
          registry-id: AWS_ACCOUNT_ID_DEV
          repo: '${APP_NAME}'
          repo-scan-on-push: true
          tag: 'latest,${CIRCLE_SHA1}'
          workspace-root: .
          requires:
            - config-pr
          filters:
            branches:
              ignore:
                - development
                - main
                - staging

jobs:
  config:
    working_directory: ~/my_dir
    docker:
      - image: cimg/node:18.4.0
    steps:
      - checkout
      - run:
          name: Create config file
          command: |
            echo '{"OWNER": "'${OWNER}'", "PASSWORD": "'${PASSWORD}'", "JWT_SECRET": "'${JWT_SECRET}'", "INTEGRATIONS": "'${INTEGRATIONS}'"}' > config.json
            ls -lah
            cat config.json
            pwd
      - persist_to_workspace:
          root: .
          paths:

```
