> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-integration/3.0/use-harness-ci/use-harness-ci/caching-ci-data/share-ci-data-across-steps-and-stages.md).

# Share CI data across steps and stages

This topic describes how you can cache and share data across steps, stages, and builds.

### Share data between steps in a stage <a href="#share-data-between-steps-in-a-stage" id="share-data-between-steps-in-a-stage"></a>

When a pipeline runs, it creates a temporary volume for each stage called a *workspace*. During initialization, the stage clones your codebase to the root of the workspace. Then, the steps in the stage run inside the root. The workspace is a volume that persists for the lifetime of the stage and enables steps in that stage to communicate and share state information. The workspace is destroyed when the stage ends.

The workspace is the current working directory for each step in the stage, and the default shared working directory for any stage is `/harness`. Any step in the stage can create, retrieve, update, and delete files in this folder. If you need to share additional volumes between steps in the stage, you can add **Shared Paths** in the [Build stage settings](/continuous-integration/use-harness-ci/use-harness-ci/set-up-build-infrastructure/ci-stage-settings.md). Paths must begin with a forward slash, such as `/vol`.

For example, the maven `m2` repo is stored in `/root/.m2` by default, which is outside the `/harness` directory. If your Build stage uses Maven, you can specify `/root/.m2` as a **Shared Path** so that all steps in that stage can access that directory.

### Share data across stages <a href="#share-data-across-stages" id="share-data-across-stages"></a>

How you share data across stages depends on the type of data you need to share. You can:

* [Use caching.](#use-caching-to-reduce-build-time)
* [Upload artifacts](/continuous-integration/use-harness-ci/use-harness-ci/build-and-upload-artifacts/build-and-upload-an-artifact.md#upload-artifacts) in one stage and pull them into another stage with, for example, a [Run step](/continuous-integration/use-harness-ci/use-harness-ci/run-step-settings.md).
* [Build and push an image](/continuous-integration/use-harness-ci/use-harness-ci/build-and-upload-artifacts/build-and-upload-an-artifact.md#build-and-push) in one stage and pull that image in another stage. For example, you could build and push a Docker image, then pull and run it in a [Background step](/continuous-integration/use-harness-ci/use-harness-ci/manage-dependencies/background-step-settings.md) and then use a [Run step](/continuous-integration/use-harness-ci/use-harness-ci/run-step-settings.md) to run integration tests on the image.

### Use caching to reduce build time <a href="#use-caching-to-reduce-build-time" id="use-caching-to-reduce-build-time"></a>

Use the following caching methods to reduce build time:

* [Docker layer caching](/continuous-integration/use-harness-ci/use-harness-ci/caching-ci-data/docker-layer-caching.md)
* [Harness Cache Intelligence](/continuous-integration/use-harness-ci/use-harness-ci/caching-ci-data/cache-intelligence.md)
* [Save and Restore Caches from S3 buckets](/continuous-integration/use-harness-ci/use-harness-ci/caching-ci-data/saving-cache.md)
* [Save and Restore Caches from GCS buckets](/continuous-integration/use-harness-ci/use-harness-ci/caching-ci-data/save-cache-in-gcs.md)
* [Save and Restore Caches from Azure storage](/continuous-integration/use-harness-ci/use-harness-ci/caching-ci-data/save-cache-azure.md)

You cannot share access credentials or other [Text Secrets](/harness-ai/use-harness-platform/secrets/add-use-text-secrets.md) with caching.

{% hint style="info" %}
**MULTILAYER CACHING**

For multilayer caching, use multiple **Restore Cache** and **Save Cache** steps according to the pattern described in [Multilayer caching](/continuous-integration/use-harness-ci/use-harness-ci/caching-ci-data/multilayer-caching.md).
{% endhint %}

### Run dependent services <a href="#run-dependent-services" id="run-dependent-services"></a>

If you need to maintain a long-running service for the duration of a stage, use a [Background step](/continuous-integration/use-harness-ci/use-harness-ci/manage-dependencies/background-step-settings.md).

### Troubleshoot caching and data sharing <a href="#troubleshoot-caching-and-data-sharing" id="troubleshoot-caching-and-data-sharing"></a>

Go to the [CI Knowledge Base](/continuous-integration/3.0/troubleshooting-and-resources/ci-articles-and-faqs/continuous-integration-faqs.md) for questions and issues related to caching, data sharing, dependency management, workspaces, shared paths, and more. For example:

* [Why are changes made to a container image filesystem in a CI step is not available in the subsequent step that uses the same container image?](/continuous-integration/3.0/troubleshooting-and-resources/ci-articles-and-faqs/continuous-integration-faqs.md#why-are-changes-made-to-a-container-image-filesystem-in-a-ci-step-is-not-available-in-the-subsequent-step-that-uses-the-same-container-image)
* [How can I use an artifact in a different stage from where it was created?](/continuous-integration/3.0/troubleshooting-and-resources/ci-articles-and-faqs/continuous-integration-faqs.md#how-can-i-use-an-artifact-in-a-different-stage-from-where-it-was-created)
* [How can I check if the cache was restored?](/continuous-integration/3.0/troubleshooting-and-resources/ci-articles-and-faqs/continuous-integration-faqs.md#how-can-i-check-if-the-cache-was-restored)
* [How do I enable Cache Intelligence?](/continuous-integration/3.0/troubleshooting-and-resources/ci-articles-and-faqs/continuous-integration-faqs.md#how-do-i-enable-cache-intelligence)
* [What is the Cache Intelligence cache storage limit?](/continuous-integration/3.0/troubleshooting-and-resources/ci-articles-and-faqs/continuous-integration-faqs.md#what-is-the-cache-intelligence-cache-storage-limit)
* [How can I share cache between different OS types (Linux/macOS)?](/continuous-integration/3.0/troubleshooting-and-resources/ci-articles-and-faqs/continuous-integration-faqs.md#how-can-i-share-cache-between-different-os-types-linuxmacos)
