You can try the following ways.
1.Save node-modules cache for each projects.
You can refer to the sample in this document:
variables:
npm_config_cache: $(Pipeline.Workspace)/.npm
steps:
- task: Cache@2
inputs:
key: 'npm | "$(Agent.OS)" | package-lock.json'
restoreKeys: |
npm | "$(Agent.OS)"
path: $(npm_config_cache)
displayName: Cache npm
- script: npm ci
You can add multiple cache tasks to create a cache for each of your node_modules folders.
2.Make multiple projects share node_modules directory.
If the module identifier passed to require() is not a core module, and
does not begin with '/', '../', or './', then Node.js starts at the
parent directory of the current module, and adds /node_modules, and
attempts to load the module from that location. Node.js will not
append node_modules to a path already ending in node_modules.
If it is not found there, then it moves to the parent directory, and
so on, until the root of the file system is reached.
Please find more details in this ticket and document. Then, you only need to cache one node_modules folder.
3.Use Self-hosted agents instead of Microsoft-hosted agents.
- In Microsoft-hosted agents, each time you run a pipeline, you get a
fresh virtual machine. The virtual machine is discarded after one
use.
- In Self-hosted agents, machine-level caches and configuration persist
from run to run , which can boost speed.
See Capabilities and limitations of Microsoft-hosted agents. If you want to install and use a self-hosted agent, you can refer to this document.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…