azure-pipelines-tasks: Error in post-job step of CacheV2 task when caching yarn packages
Required Information
Entering this information will route you directly to the right team and expedite traction.
Question, Bug, or Feature?
Type: Bug
Enter Task Name: CacheV2 (https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/CacheV2)
Environment
-
Server - Azure Pipelines
- Account name: markethype
- Team project name: MarketHype
- Build ID: 1563
- URL: https://dev.azure.com/markethype/MarketHype/_build/results?buildId=1563
-
Agent - Hosted:
- Agent Queue name: Azure Pipelines (https://dev.azure.com/markethype/MarketHype/_settings/agentqueues?queueId=17&view=jobs)
Issue Description
Using the CacheV2 task to cache Yarn packages, we’re getting an error in the post-job step of the cache task.
The task is defined exactly as in the docs.
variables:
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
steps:
- task: Cache@2
inputs:
key: 'yarn | "$(Agent.OS)" | yarn.lock'
restoreKeys: |
yarn | "$(Agent.OS)"
path: $(YARN_CACHE_FOLDER)
displayName: Cache Yarn packages
We’re using the vs2017-win2016
image.
Error logs
Starting: Cache Yarn packages
==============================================================================
Task : Cache
Description : Cache files between runs
Version : 2.0.0
Author : Microsoft Corporation
Help : https://aka.ms/pipeline-caching-docs
==============================================================================
Resolving key:
- yarn [string]
- "Windows_NT" [string]
- common/config/rush/yarn.lock [file] --> 0551FA989D7CDCB2101F1397E8E7C5468396D4C72935548B6A74BEB126F0296F
Resolved to: yarn|"Windows_NT"|57F7K6kT3NtH/ZuSuWsxueTn4wCxuYls973WEnqCJgE=
Information, ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session 06101a50-81b0-41b6-ab13-b130ee5c98ae
Information, Getting a pipeline cache artifact with one of the following fingerprints:
Information, Fingerprint: `yarn|"Windows_NT"|57F7K6kT3NtH/ZuSuWsxueTn4wCxuYls973WEnqCJgE=`
Information, There is a cache miss.
tar: D\:\\a\\1\\.yarn: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
Information, ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session 06101a50-81b0-41b6-ab13-b130ee5c98ae
##[error]Process returned non-zero exit code: 2
Finishing: Cache Yarn packages
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 19
- Comments: 30 (1 by maintainers)
@jfheins thanks for the hint.
Current configuration works for me in cloud-hosting:
Same issue here, but this time with npm
Starting: Cache npm Task : Cache Description : Cache files between runs Version : 2.0.1 Author : Microsoft Corporation Help : https://aka.ms/pipeline-caching-docs Resolving key:
npm|"Windows_NT"|2DZ3WcfStD108j8qipq/0v97TF5eyy6fpvtPYfpDrZM=
Information, There is a cache miss. tar: Cannot change to directory E:\Agents\3\283\s\node_modules: No such file or directory tar: Error is not recoverable: exiting now Information, ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session XXXXXXXX282-485c-a6f4-b92a59ed4955 ##[error]Process returned non-zero exit code: 2 Finishing: Cache npmSame issue here on a hosted linux agent
Try adding an
s
between$(Pipeline.Workspace)
and.yarn
, so variable goes from:To:
This is because when using
checkout: self
, it checks out the repository to$(Pipeline.Workspace)/s
, as is explained here. Unless your using magic, your .yarn folder should be inside the repository.No, this task is especially good for the Azure hosted agents. In a self hosted scenario, most of the caching works without this task. (For example: yarn has a machine wide global cache that persists in a self hosted agent)
The tricky thing is to get the cache directory right. For example, an Azure agent mighthave the yarn cache in “/home/vsts/.cache/yarn” while a self hosted might need “/home/AzDevOps/.cache/yarn”
I’d recommend to include a step that logs out the cache directories for easier troubleshooting:
I was running into this exact issue and fixed it by adding YARN_CACHE_FOLDER to the pipeline variables.
I had the Cache task as part of a task group and in the pipeline that uses the task group, there is a required field that asks for the value of
YARN_CACHE_FOLDER
which is used as ‘path’ for the Cache task. Filled in the field with$(Pipeline.Workspace)/.yarn
but the post-job kept failing with same error as above.Once I also defined
YARN_CACHE_FOLDER=$(Pipeline.Workspace)/.yarn
in the pipeline variables, the post-job stopped failing.@johnterickson you are correct. The variable wasn’t being set.
After changing this part:
to this:
I stopped experiencing this issue.
I’m not sure why the pipeline I created started throwing the
/home/vsts/work/1/.yarn: Cannot open: No such file or directory
error as I use the exact same setup other places, with$(Pipeline.Workspace)/.yarn
. I tried using different vmImages with no luck. Here’s how I solved it for the ones interested.