Is your build time on azure devops waaay to long? Tired of waiting on your build? Guess What? You’re at the right place!
Quick introduction of the current solutions that can be used:
Option 1 (my current favorite)
https://marketplace.visualstudio.com/items?itemName=1ESLighthouseEng.PipelineArtifactCaching
Option 2
Caching with Microsoft DevLabs
Step 1: Adding the task
Step 2: Task order
Add the task before the npm install
Step 3: Configuring the task for npm
key file: **/package-lock.json, !**/node_modules/**/package-lock.json
target folder: **/node_modules, !**/node_modules/**/node_modules
Feed: Create a feed if you don’t have one:
How to create a feed
After the feed has been made, simply select the feed in the dropdown:
That’s all for the restore and save the artifact task!
Let’s move on to your npm install
Step 1: Add a bash Task (Yeah I like bash 💩) and make it look like this:
Step 2: Configuring some settings
Under “Advanced” add your working directory, this is where your package.json is lives
Step 3: Finishing touch
Under “Run this task” Select “Custom conditions” and add the following custom condition:
ne(variables['CacheRestored'], 'true')
This will simply skip the npm install if the cache is already restored by our previous task!
Voila!
Your npm install should be skipped when building the second time!
Happy coding! :)