This topic describes how to configure cache settings for a Flow pipeline.
Cache settings
During the execution of a Flow pipeline, each job node creates a new build environment that is destroyed after the build completes. To prevent the repeated downloading of build dependencies during pipeline execution and to enhance build efficiency, Flow provides the cache settings feature. You can customize cache directories to enable cache sharing across multiple pipeline job runs.
For example, when executing npm install
in a Node.js build job, ./node_modules
is generated in the project, and the cache is stored in /root/.npm
. You can preserve /root/.npm
for quicker subsequent downloads.
Configure cache directories
Navigate to the pipeline editing page, choose
, and configure the Cache Directory. Flow does not support cache sharing between jobs within the same pipeline run. Flow's caching capability is designed to address the issue of downloading dependencies across multiple job runs.Flow caches the following directories by default. You can enable or disable the default cache directories and modify them as needed.
Management tool
Cache directory
Maven
/root/.m2
Gradle
/root/.gradle/caches
NPM
/root/.npm
Yarn
/root/.yarn
go mod
/go/pkg/mod
Other cache
/root/.cache
You can add custom cache directories, which must adhere to the following rules:
Do not specify directories such as
/
,/root
,/root/workspace
, or/root/workspace/
.Do not include
..
in the directory path, as in/root/abc/..
, which is invalid.The directory must be valid. For example,
/root/%\&dfaf
is not a valid directory.
If you need to cache a directory or file under the workspace
/root/workspace
during the build process, you can copy it to another directory under/root
and designate it as the cache directory. The following figures show an example:
Use cache in build jobs
After cache directories are configured, you can decide whether to prioritize using the cache when executing the pipeline with the corresponding build command parameters.
When building with NPM, run the following command to install dependencies:
// Prioritize using the cache during the build npm install --prefer-offline --no-audit
When building with Yarn, run the following command to install dependencies:
// Prioritize using the cache during the build yarn install --prefer-offline