4

For example, cache the contents of node_modules unless package.json changes.

AppVeyor supports this, where somehow it knows that package.json changed and will invalidate its cached node_modules folder that it copies into the VM build work area.

janpio
  • 10,645
  • 16
  • 64
  • 107
enorl76
  • 2,562
  • 1
  • 25
  • 38
  • "We are actively looking into a build caching solution for Azure Pipelines, we have done some initial design work and hope to start work on it in the new year." https://github.com/Microsoft/azure-pipelines-tasks/issues/9190#issuecomment-450232972 – mloskot Jan 29 '19 at 08:52

1 Answers1

0

This can be now achieved by using the Cache task. More info can be found on MSDN article (it also has many examples for well-known apps) but in general it goes like this:

step screenshot

or in YAML

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

The idea is that you specify a cache key, which could be a string or a file content (exactly what you're asking for) and the path to cache. You don't need a separate restore task, this one works in both directions.

Note, that for this example you should also define the npm_config_cache environment variable.

Andrey Stukalin
  • 5,328
  • 2
  • 31
  • 50