Efficiently cache dependencies in Jenkins pipelines to reduce build times by reusing libraries and artifacts across runs.
Efficient dependency caching in a CI/CD pipeline can dramatically reduce build times by reusing previously downloaded libraries and generated artifacts. In Jenkins, the Job Cacher Plugin enables you to store and restore cache items—such as node_modules—across pipeline runs, even in ephemeral environments like containers.
Caching avoids repeated downloads and installations, leading to faster feedback loops and lower resource usage. It’s especially helpful for languages and frameworks with large dependency trees (e.g., Node.js, Python).
Commit and push your updated Jenkinsfile. On the next build, you’ll see cache operations in the console:
Copy
Ask AI
Searching cache in job specific caches...Searching cache in default caches...Skip restoring cache as no up-to-date cache exists> node -vv22.6.0> npm install --no-auditup to date in 1s...Stashed 4993 file(s)Creating cache for node_modules (npm-dependency-cache) [id: 3ec03583f8eaec275c2183db769ff47]Cache created in 164ms
After success, the Blue Ocean UI highlights each stage:
In the classic UI, inspect cache logs under Build Details:
Console output for the Installing Dependencies stage:
Copy
Ask AI
{cache for node_modules (npm-dependency-cache) with id ...} Searching cache in job specific caches...{cache for node_modules (npm-dependency-cache) with id ...} got hash a47b9ef602dbc79d72ab6385105e0142 for /var/lib/jenkins/.../package-lock.json{cache for node_modules ...} Restoring cache...> npm install --no-auditup to date in 1s...{cache for node_modules ...} Skipped saving cache as it is up to date
On subsequent runs, the plugin will restore the cache automatically and skip redundant installations—saving precious build time.