Share CI data across steps and stages
This topic describes how you can 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
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. 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
How you share data across stages depends on the type of data you need to share. You can:
Upload artifacts in one stage and pull them into another stage with, for example, a Run step.
Build and push an image 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 and then use a Run step to run integration tests on the image.
Use caching to reduce build time
Use the following caching methods to reduce build time:
You cannot share access credentials or other Text Secrets with caching.
Run dependent services
If you need to maintain a long-running service for the duration of a stage, use a Background step.
Troubleshoot caching and data sharing
Go to the CI Knowledge Base for questions and issues related to caching, data sharing, dependency management, workspaces, shared paths, and more. For example:
Last updated
Was this helpful?