pcnate
pcnate

Reputation: 1774

Cache Chocolatey packages in Azure Devops

TLDR;

I have an Azure Devops Pipeline that uses chocolatey to install dependencies. I would like to cache downloaded chocolatey packages similar to how node dependencies are cached (see below) or use a caching proxy server.

  1. Is it possible to cache downloaded packages from chocolatey to be available at the next run?

  2. If that is not currently easily possible, then is it possible to run a caching proxy server similar to AptCacherNg for chocolatey packages?

Current Setup

I currently have a pipeline setup in Azure Devops that requires packages from chocolatey community. The step runs the equivalent of:

choco install nasm --confirm --no-progress

enter image description here

I am caching node dependencies using the following:

steps:
- task: Cache@2
  displayName: 'Cache npm packages'
  inputs:
    key: '**/package-lock.json, !**/node_modules/**/package-lock.json, !**/.*/**/package-lock.json'
    path: '$(System.DefaultWorkingDirectory)/node_modules'

I have considered whether it was possible to modify the keys for this to check the choco packages or use a duplicate step that uses this plugin but I don't know specifically how to do this.

Backgound

Recently, one of the modules website went offline for a few hours. While it was offline I noticed that in the logs it stated that licensed users likely didn't have the issue as they cache packages. I checked into license pricing and it seems that there is a reasonable $96/year cost for a single user license of up to 8 machines but in the license it states that using this would violate the terms for business usage. The business license is $16/year/machine with a minimum of 100 machines. $1600/year is a bit more than I want to pay at this time for such a small dev team that only needs a few packages installed. They suggested community edition.

Upvotes: 1

Views: 1231

Answers (1)

qbik
qbik

Reputation: 5928

Choco has a handy --cache option that lets you specify the cache location. Use this option together with a dedicated Cache step:

- task: Cache@2
  displayName: 'Cache choco'
  inputs:
    key: 'path_to_a_file_or_just_a_string_that_you_update_manually'
    path: '$(System.DefaultWorkingDirectory)/choco_cache'
- script: choco install nasm --confirm --no-progress --cache $(System.DefaultWorkingDirectory)/choco_cache
  displayName: 'install choco packages'

Upvotes: 4

Related Questions