0
votes

I'm trying to cache my npm packages in an Azure Pipeline YAML. I used this code from Microsoft: https://docs.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#nodejsnpm

Here's part of my YAML file:

steps:
  - task: NodeTool@0
    displayName: 'Use Node 12.x'
    inputs:
        versionSpec: 12.18.3
        checkLatest: false
  
  - task: Npm@1
    displayName: 'npm install'
    inputs:
        workingDir: WebApp
        verbose: false

  - task: Cache@2
    inputs:
        key: 'npm | "$(Agent.OS)" | package-lock.json'
        restoreKeys: npm | "$(Agent.OS)"
        path: $(npm_config_cache)
    displayName: Cache NPM packages

When I run the pipeline it fails with this message:

A task is missing. The pipeline references a task called 'Cache'. This usually indicates the task isn't installed, and you may be able to install it from the Marketplace: https://marketplace.visualstudio.com. 

I tried installing the Cache task from the Microsoft Marketplace but it wasn't available. I'm using Azure DevOps Server 2019 with the June update. The Cache task hasn't been deprecated and should work with my version of Azure DevOps Server according to this page: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/cache?view=azure-devops. How do I install the Cache task?

UPDATE:

I found a post on a Microsoft developer forum that covers the same issue: https://developercommunity.visualstudio.com/content/problem/1092245/cache-task-not-available-on-azure-devops-server.html. Apparently the Cache task is not currently available on Azure DevOps Server 2019. I'll have to look for a workaround. Talk about ridiculous. Microsoft doesn't make the Cache task available and puts nothing on their website about it.

1
is CacheBeta@0 works?Shayki Abramczyk
I tried CacheBeta and got the same error.mdailey77
I guess the Cache doesn't exist in ado server 2019 yetShayki Abramczyk
There's no need to cache when using private agents -- the agent already maintains a cache. The only purpose of caching is for Microsoft-hosted agents to avoid having to restore from NuGet/NPM on every build.Daniel Mann
@DanielMann Thanks. I didn't know that. Is there a way to speed up the npm install? It takes about 5 minutes for my npm install build step to complete, which seems like a long time.mdailey77

1 Answers

0
votes

If you are using self-hosted agents. You can add checkout step in your pipeline and set the clean attribute to false(default is true if not specified). So that the installed dependencies in the source folder will not be cleaned for next build. And it will speed up the npm install task. See below:

steps:
  - checkout: self
    clean: false

  - task: NodeTool@0
    displayName: 'Use Node 12.x'
    inputs:
        versionSpec: 12.18.3
        checkLatest: false
  
  - task: Npm@1
    displayName: 'npm install'
    inputs:
        workingDir: WebApp
        verbose: false

Check here for more information.