Skip to content

Fix CacheV2 task to ensure cache directory exists for yarn packages #21034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented May 19, 2025

The Issue

The CacheV2 task was failing during the post-job execution phase when caching yarn packages. The error occurred because the SavePipelineCacheV0 agent plugin attempted to archive a directory that didn't exist:

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
##[error]Process returned non-zero exit code: 2

This happens specifically on the first run when:

  1. There is a cache miss (no previous cache to restore)
  2. The directory specified in the path input doesn't exist
  3. The post-job execution tries to save the cache but fails because the directory doesn't exist

The Solution

Added a JavaScript script that runs before the agent plugin to ensure the cache directory exists:

  1. Created restoreCache.js that checks if the directory exists and creates it if needed
  2. Modified task.json to include Node execution targets (10, 16, and 20) while preserving the agent plugin functionality
  3. Added proper package.json for dependency management
  4. Added README.md with documentation and usage examples

This ensures that when users set up caching for Yarn packages as described in the documentation:

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

The task will now work properly even on the first run when the directory doesn't exist yet.

Fixes #12892.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Error in post-job step of CacheV2 task when caching yarn packages Fix CacheV2 task to ensure cache directory exists for yarn packages May 19, 2025
@Copilot Copilot AI requested a review from fadnavistanmay May 19, 2025 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in post-job step of CacheV2 task when caching yarn packages
2 participants