Is it possible to use Cache with the NodeTool task on order to skip downloading a specific version of tools and use a version shared across multiple pipelines? Right now NodeTool task occasionally fails to download the tool which causes intermittent errors. I'm a little unclear on how the Cache task works to allow another task to conditionally run the first time, and also where/how to get the cache to restore the Node JS tool to the appropriate path consistent with what NodeTool would do. This is a pipeline hosted in DevOps.
Note I'm not asking about catching NPM packages. Just a version of NodeJS tool supplied by NodeTool task.
You can't use the Cache task, because it will only cache things within the working directory of the job.
But it's relatively easy to re-populate the hosted tools cache at the start of the job.
The agent keeps a toolcache folder under which each tools installer puts the contents and then updates the path. The path to the tools cache is stored in a predefined variable:
Agent.ToolsDirectory.This folder uses a predefined structure:
In the case of Node 16.19.1 this ends up here:
$(Agent.ToolsDirectory)/node/16.19.1/x64If you zip up the folder
$(Agent.ToolsDirectory)/node/16.19.1/and store it somewhere (Azure DevOps Universal Artifacts comes to mind), you can restore the folder at the start of the job. TheUseNodetask will detect the presence of the restored files and it will automatically use it.You can run a pipeline once to create the zip and upload it to universal artifacts. You can then use this artefact from any other workflow that needs to restore this specific tool.
Something like:
And then to restore:
Make sure you grant the
Project Collection Build Servicecontributor permissions on the package feed.