Skip to content

Error in post-job step of CacheV2 task when caching yarn packages #12892

Closed
@c-eliasson

Description

@c-eliasson

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

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

Activity

jmaragon

jmaragon commented on Jun 10, 2020

@jmaragon

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 [string]
  • "Windows_NT" [string]
  • ./product/package.json [file] --> 66FF0092057590D58252E7A1365E9520D41F83083CE0C8C1DA0E038DC4C2D9D1
    Resolved to: npm|"Windows_NT"|2DZ3WcfStD108j8qipq/0v97TF5eyy6fpvtPYfpDrZM=
    Information, ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session xxxxxxxxxx-1282-485c-a6f4-b92a59ed4955
    Information, Getting a pipeline cache artifact with one of the following fingerprints:
    Information, Fingerprint: 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 npm
bradringel

bradringel commented on Jun 10, 2020

@bradringel

Same issue here on a hosted linux agent

2020-06-09T21:30:32.6150811Z ##[section]Starting: Cache yarn packages
2020-06-09T21:30:32.6163777Z ==============================================================================
2020-06-09T21:30:32.6164193Z Task         : Cache
2020-06-09T21:30:32.6164523Z Description  : Cache files between runs
2020-06-09T21:30:32.6164828Z Version      : 2.0.1
2020-06-09T21:30:32.6165145Z Author       : Microsoft Corporation
2020-06-09T21:30:32.6165519Z Help         : https://aka.ms/pipeline-caching-docs
2020-06-09T21:30:32.6165941Z ==============================================================================
2020-06-09T21:30:32.9975064Z Resolving key:
2020-06-09T21:30:33.0154988Z  - yarn      [string]
2020-06-09T21:30:33.0162685Z  - "Linux"   [string]
2020-06-09T21:30:33.0743802Z  - yarn.lock [file] --> EA85735E476B7CE9FF55138A52CE89B7299F92856B621075773F035440C87D93
2020-06-09T21:30:33.0785039Z Resolved to: yarn|"Linux"|QlvZU5gmusF+bBuImFOlW68Qf4aNmdJ1pmhH2LChb5o=
2020-06-09T21:30:33.6622757Z Information, ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session c6edd63d-1238-44dd-a471-3439ac2f402e
2020-06-09T21:30:33.6861181Z Information, Getting a pipeline cache artifact with one of the following fingerprints:
2020-06-09T21:30:33.6862267Z Information, Fingerprint: `yarn|"Linux"|QlvZU5gmusF+bBuImFOlW68Qf4aNmdJ1pmhH2LChb5o=`
2020-06-09T21:30:34.2316763Z Information, There is a cache miss.
2020-06-09T21:30:34.2834153Z tar: /home/vsts/work/1/.yarn: Cannot open: No such file or directory
2020-06-09T21:30:34.2834821Z tar: Error is not recoverable: exiting now
2020-06-09T21:30:34.5635719Z Information, ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session c6edd63d-1238-44dd-a471-3439ac2f402e
2020-06-09T21:30:34.5689658Z ##[error]Process returned non-zero exit code: 2
2020-06-09T21:30:34.5844564Z ##[section]Finishing: Cache yarn packages```
stevewarsa

stevewarsa commented on Jun 19, 2020

@stevewarsa

Same issue here with yarn - it is in some autogenerated task after my WAR deploy is done - the task is called "Post-job: Cache":

tar: /blah/blahgent/_work/1/s//node_modules, !/node_modules/**/node_modules: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
Information, ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session 18de2057-e96c-4ff9-9091-595b9595f5cf
##[error]Process returned non-zero exit code: 2
Finishing: Cache

Any clue how to solve?

lesterchan

lesterchan commented on Jun 24, 2020

@lesterchan

Came in here to +1 to this, below is my config:

variables:
  - name: yarnCacheFolder
    value: $(Pipeline.Workspace)/.yarn

  - task: Cache@2
    displayName: Cache Yarn Packages
    inputs:
      key: yarn | $(Agent.OS) | yarn.lock
      restoreKeys: |
        yarn | $(Agent.OS)
        yarn
      path: $(yarnCacheFolder)

Post-job: Cache Yarn Packages will throw an error

/home/vsts/work/1/.yarn: Cannot open: No such file or directory
jfheins

jfheins commented on Aug 4, 2020

@jfheins

For me it works, but I have set the directory directly because I found no suitable pipeline variable:

      - task: Cache@2
        inputs:
          key: 'yarn | "$(Agent.OS)" | Frontend/.../yarn.lock'
          restoreKeys: yarn | "$(Agent.OS)"
          path: /home/vsts/.cache/yarn
        displayName: Cache Yarn packages

I'm using a hosted agent (ubuntu-18.04); maybe this works for you as well.
One can print the relevant directory for yarn with yarn cache dir

jotatoledo

jotatoledo commented on Aug 5, 2020

@jotatoledo

@jfheins thanks for the hint.

Current configuration works for me in cloud-hosting:

pool:
  vmImage: 'ubuntu-latest'
variables:
 - name: YARN_CONFIG_CACHE
    value: /home/vsts/.cache/yarn/v6
...
- task: Cache@2
  displayName: Cache node modules
  inputs:
    key: 'yarn | "$(Agent.OS)" | yarn.lock'
    restoreKeys: |
      yarn | "$(Agent.OS)"
    path: $(YARN_CONFIG_CACHE)
github-actions

github-actions commented on Feb 1, 2021

@github-actions

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

bradringel

bradringel commented on Feb 2, 2021

@bradringel

Bumping because this is still happening and I don't think it should be closed

28 remaining items

DxTa

DxTa commented on Jun 17, 2024

@DxTa

@nickshanks347 's comment is really helpful. In deed, the same also happening to other tool such as pip

Evanion

Evanion commented on Aug 27, 2024

@Evanion

I tried

variables:
 NPM_CACHE_FOLDER: $(Pipeline.Workspace)/s/.npm
# ...
steps:
 - task: Cache@2
    displayName: Cache NPM packages
    inputs:
      key: '"npm" | "$(Agent.OS)" | package-lock.json'
      restoreKeys: |
        "npm" | "$(Agent.OS)"
        "npm"
      path: $(NPM_CACHE_FOLDER)
      cacheHitVar: NPM_CACHE_RESTORED

But I get

Post-job: Cache NPM packages

[View raw log](https://dev.azure.com/landshypotek/980d789b-7245-4c89-a4a0-320898842fa4/_apis/build/builds/9637/logs/19)
Starting: Cache NPM packages
==============================================================================
Task         : Cache
Description  : Cache files between runs
Version      : 2.198.0
Author       : Microsoft Corporation
Help         : https://aka.ms/pipeline-caching-docs
==============================================================================
Resolving key:
 - "npm"             [string]
 - "Linux"           [string]
 - package-lock.json [file] --> 0C9C69F14CFB03BABFC87109EECCB2B787FBAD0ECFC7E1F9F823A953E0A5303E
Resolved to: "npm"|"Linux"|NyzAW704Sn4J2Y1PCdbgFC5xaendrqBTYW+d+xSeAhY=
Using default max parallelism.
Using default max parallelism.
Max dedup parallelism: 192
DomainId: 0
ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session ab82fec9-6c06-4dc7-9d91-1f0827ba36b5
Hashtype: Dedup64K
Getting a pipeline cache artifact with one of the following fingerprints:
Fingerprint: `"npm"|"Linux"|NyzAW704Sn4J2Y1PCdbgFC5xaendrqBTYW+d+xSeAhY=`
There is a cache miss.
tar: /home/vsts/work/1/s/.npm: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session ab82fec9-6c06-4dc7-9d91-1f0827ba36b5
##[error]Process returned non-zero exit code: 2
Finishing: Cache NPM packages

I would expect the post-job to create the folder if it doesn't exist.

jfheins

jfheins commented on Aug 29, 2024

@jfheins

I would expect the post-job to create the folder if it doesn't exist.

The output is telling you that the directory with the stuff you want to cache does not exist. (i.e. there is nothing to cache)
Have you tried to run npm --global cache verify in the pipeline to have npm output the cache directory?

AlexisJacob1

AlexisJacob1 commented on Oct 7, 2024

@AlexisJacob1

Hi,
We're having the same issue, but with NuGet packages.

2024-10-07T12:06:28.2977763Z ##[section]Starting: NuGet Cache
2024-10-07T12:06:28.2990900Z ==============================================================================
2024-10-07T12:06:28.2991333Z Task         : Cache
2024-10-07T12:06:28.2991508Z Description  : Cache files between runs
2024-10-07T12:06:28.2991716Z Version      : 2.198.0
2024-10-07T12:06:28.2991911Z Author       : Microsoft Corporation
2024-10-07T12:06:28.2992096Z Help         : https://aka.ms/pipeline-caching-docs
2024-10-07T12:06:28.2992514Z ==============================================================================
2024-10-07T12:06:28.7416432Z Resolving key:
2024-10-07T12:06:28.7601309Z  - nuget                                       [string]
2024-10-07T12:06:28.7646429Z  - "Windows_NT"                                [string]
2024-10-07T12:06:29.3223086Z  - **/packages.lock.json,!**/bin/**,!**/obj/** [file pattern; matches: 1]
2024-10-07T12:06:29.3250490Z    - s\Exposed-API-v2\packages.lock.json --> EA02F2C348E6430278923F99E7BD2C6199A615EA44D8C5C04AA1ADAB8EDE1223
2024-10-07T12:06:29.3275286Z Resolved to: nuget|"Windows_NT"|14ENw8o70BCYT0eXNadg8S+3a/Qg6UX21F0XdjBe9oI=
2024-10-07T12:06:29.3902883Z Using default max parallelism.
2024-10-07T12:06:30.9012730Z tar: could not chdir to 'D:\a\1\.nuget\packages'
2024-10-07T12:06:30.9014291Z 
2024-10-07T12:06:30.9015271Z Using default max parallelism.
2024-10-07T12:06:30.9016140Z Max dedup parallelism: 192
2024-10-07T12:06:30.9016911Z DomainId: 0
2024-10-07T12:06:30.9018238Z ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session d190de86-e08b-403a-a797-9e5695b45cf8
2024-10-07T12:06:30.9019259Z Hashtype: Dedup64K
2024-10-07T12:06:30.9020154Z Getting a pipeline cache artifact with one of the following fingerprints:
2024-10-07T12:06:30.9021249Z Fingerprint: `nuget|"Windows_NT"|14ENw8o70BCYT0eXNadg8S+3a/Qg6UX21F0XdjBe9oI=`
2024-10-07T12:06:30.9022151Z There is a cache miss.
2024-10-07T12:06:30.9454673Z ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session d190de86-e08b-403a-a797-9e5695b45cf8
2024-10-07T12:06:30.9509135Z ##[error]Process returned non-zero exit code: 1
2024-10-07T12:06:30.9523659Z ##[section]Finishing: NuGet Cache

Can we have an update on this ?
By the way, I agree with @Evanion when he say:

I would expect the post-job to create the folder if it doesn't exist.

jfheins

jfheins commented on Oct 9, 2024

@jfheins

With nuget, the process to get it working is the same:

  • Identify the relevant directory (for nuget: run dotnet nuget locals all --list within the pipeline)
  • Use a relevant directory in the cache task

Optional: Check what pipeline variables exist and maybe you can replace part of the absolute path with a variable

github-actions

github-actions commented on Apr 10, 2025

@github-actions

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @rfink@jmaragon@Evanion@lesterchan@loxy

    Issue actions

      Error in post-job step of CacheV2 task when caching yarn packages · Issue #12892 · microsoft/azure-pipelines-tasks