This plugin provides caching for dependencies and build artefacts to reduce build execution times. This is especially useful for Jenkins setups with ephemeral executors which always start from a clean state, such as container based ones.
- Store caches on the Jenkins controller, AWS S3 and S3 compatible services
- Use caching in pipeline and freestyle jobs
- Define maximum cache sizes so that the cache won't grow indefinitely
- View job specific caches on job page
jenkins.plugins.itemstorage.ItemStorage
for adding custom cache storagesjenkins.plugins.jobcacher.Cache
for adding custom caches
By default, the plugin is configured to use on-controller storage for the cache. In addition, a storage implementation for Amazon S3 and S3 compatible services is also available.
The storage type can be configured in the global configuration section of Jenkins.
The following cache configuration options apply to all supported job types.
Option | Mandatory | Description |
---|---|---|
maxCacheSize |
no | The maximum size in megabytes of all configured caches that Jenkins will allow until it deletes all completely and starts the next build from an empty cache. This prevents caches from growing indefinitely with the downside of periodic fresh builds without a cache. Set to zero or empty to skip checking cache size. |
defaultBranch |
no | If the current branch has no cache, it will seed its cache from the specified branch. Leave empty to generate a fresh cache for each branch. |
caches |
yes | Defines the caches to use in the job (see below). |
Option | Mandatory | Default value | Description |
---|---|---|---|
path |
yes | The path to cache. It can be absolute or relative to the workspace. | |
cacheName |
no | The name of the cache. Useful if caching the same path multiple times in a pipeline. | |
includes |
no | **/* |
The pattern to match files that should be included in caching. |
excludes |
no | The pattern to match files that should be excluded from caching. | |
useDefaultExcludes |
no | true |
Whether to use default excludes (see DirectoryScanner.java#L170 for more details). |
cacheValidityDecidingFile |
no | The workspace-relative path to one or multiple (by using a glob pattern) files which should be used to determine whether the cache is up-to-date or not. Only up-to-date caches will be restored and only outdated caches will be created. | |
compressionMethod |
yes | TARGZ |
The compression method (NONE , ZIP , TARGZ , TAR_ZSTD ) to use. |
The plugin provides a "Job Cacher" build environment. The cache(s) will be restored at the start of the build and updated at the end of the build.
The plugin provides a cache
build step that can be used within the pipeline definition.
The cache(s) will be restored before calling the closure and updated after executing it.
cache(maxCacheSize: 250, defaultBranch: 'develop', caches: [
arbitraryFileCache(path: 'node_modules', cacheValidityDecidingFile: 'package-lock.json')
]) {
// ...
}
If you use the plugin within a Docker container through the Docker Pipeline plugin, the path to cache must be located within the workspace. Everything outside is not visible to the plugin and therefore not cacheable.
See releases