0

How to use this cache for python requirements caching ? Will this cache task works if we use Hosted Agent for build

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107

1 Answers1

1

In documentation you have examples how to use cahce with requirements.txt file.

variables:
  PIP_CACHE_DIR: $(Pipeline.Workspace)/.pip

steps:
- task: Cache@2
  inputs:
    key: 'python | "$(Agent.OS)" | requirements.txt'
    restoreKeys: | 
      python | "$(Agent.OS)"
      python
    path: $(PIP_CACHE_DIR)
  displayName: Cache pip packages

- script: pip install -r requirements.txt

And Pipefile.lock:

variables:
  PIPENV_CACHE_DIR: $(Pipeline.Workspace)/.pipenv

steps:
- task: Cache@2
  inputs:
    key: 'python | "$(Agent.OS)" | Pipfile.lock'
    restoreKeys: | 
      python | "$(Agent.OS)"
      python
    path: $(PIPENV_CACHE_DIR)
  displayName: Cache pipenv packages

- script: pipenv install

Taks should run without any issue on Self Hosted Agents if you have all prerequisites installed:

enter image description here

What is worth to mention this doesn't work with Azure DevOps Server.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107