Skip to main content

Share CI data across steps and stages

This topic describes how you can share CI data across steps and stages.

Share data between steps in a stage

When a pipeline runs, it creates a temporary volume 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

You must use one of the following caching methods to share data across stages:

You cannot share access credentials or other Text Secrets across stages. For complete end-to-end examples, go to the following:

If you need to maintain a long-running service for the duration of a stage, use a Background step.

Docker layer caching

Remote Docker layer caching can dramatically improve build times by sharing layers across pipelines, stages, and steps. You can set up Docker layer caching in the following steps:

For more recommendations for optimizing Docker images, go to Optimize and enhance CI pipelines.