Dheeraj Palagiri
Dheeraj Palagiri

Reputation: 1879

tar: could not chdir to 'D:\a\1\docker'

I am trying to use Cache Task in Azure Pipelines for the Docker setup. According to the documentation I need to set below parameters:

 - task: Cache@2
      inputs:
        key: 'docker | "$(Agent.OS)" | cache'
        path: '$(Pipeline.Workspace)/docker'

Unfortunately, the post-job for Cache task always failing with this error. Any suggestions?

Starting: Cache
==============================================================================
Task         : Cache
Description  : Cache files between runs
Version      : 2.0.1
Author       : Microsoft Corporation
Help         : https://aka.ms/pipeline-caching-docs
==============================================================================
Resolving key:
 - docker       [string]
 - "Windows_NT" [string]
 - cache        [string]
Resolved to: docker|"Windows_NT"|cache
ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session xxxx
Getting a pipeline cache artifact with one of the following fingerprints:
Fingerprint: `docker|"Windows_NT"|cache`
There is a cache miss.
tar: could not chdir to 'D:\a\1\docker'

ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session xxxx
##[error]Process returned non-zero exit code: 1
Finishing: Cache
  

Update: After making the changes in creating the direction based on the suggested answer the cache has been hit but the size of it is 0.0MB. Do we need to take care of copy ourselves?

Starting: Cache
==============================================================================
Task         : Cache
Description  : Cache files between runs
Version      : 2.0.1
Author       : Microsoft Corporation
Help         : https://aka.ms/pipeline-caching-docs
==============================================================================
Resolving key:
 - docker       [string]
 - "Windows_NT" [string]
 - cache        [string]
Resolved to: docker|"Windows_NT"|cache
ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session xxxxxx
Getting a pipeline cache artifact with one of the following fingerprints:
Fingerprint: `docker|"Windows_NT"|cache`
There is a cache hit: `docker|"Windows_NT"|cache`
Used scope: 3;xxxx;refs/heads/master;xxxx
Entry found at fingerprint: `docker|"Windows_NT"|cache`

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21


Extracting archive: 
Expected size to be downloaded: 0.0 MB
**Downloaded 0.0 MB out of 0.0 MB (214%).
Downloaded 0.0 MB out of 0.0 MB (214%).**

Download statistics:
Total Content: 0.0 MB
Physical Content Downloaded: 0.0 MB
Compression Saved: 0.0 MB
Local Caching Saved: 0.0 MB
Chunks Downloaded: 3
Nodes Downloaded: 0

--
Path = 
Type = tar
Code Page = UTF-8

Everything is Ok




  

Upvotes: 3

Views: 4172

Answers (2)

Lavanya
Lavanya

Reputation: 41

I got the same issue. After creating the cache path folder before cache task, error is resolved.

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'New-Item -ItemType directory -Path $(Pipeline.Workspace)/docker'

As mentioned, still the cache itself didn't work as expected. I modified the cache folder, cache key and cache path to different values, since cache is immutable. And Cache key and restoreKeys are set to same value.

pool:
  vmImage: windows-2019

variables:
  MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/testcache1/.m2/repository
  MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'

steps:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'New-Item -ItemType directory -Path $(MAVEN_CACHE_FOLDER)'

- task: Cache@2
  inputs:
    key: mykeyazureunique
    restoreKeys: mykeyazureunique
    path: $(MAVEN_CACHE_FOLDER)
  displayName: Cache Maven local repo

- task: MavenAuthenticate@0
  displayName: Authenticate Maven to Artifacts feed
  inputs:
    artifactsFeeds: artifacts-maven
    #mavenServiceConnections: serviceConnection1, serviceConnection2 # Optional

- task: Maven@3
  displayName: Maven deploy into Artifact feed
  inputs:
    mavenPomFile: 'pom.xml'
    goals: 'clean install'
    mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'
    publishJUnitResults: false
    javaHomeOption: 'JDKVersion'
    mavenVersionOption: 'Default'
    mavenAuthenticateFeed: false
    effectivePomSkip: false
    sonarQubeRunAnalysis: false

Note: Cache will be set only if the job is successful.

If the cache is saved successfully, then you will see below message in the Post-job:Cache

Content upload statistics:
Total Content: 41.3 MB
Physical Content Uploaded: 17.9 MB
Logical Content Uploaded: 20.7 MB
Compression Saved: 2.8 MB
Deduplication Saved: 20.7 MB
Number of Chunks Uploaded: 265
Total Number of Chunks: 793

Now the cache is set properly, we have to make sure Cache location is picked up while execution. First thing, verify that cache is restored properly. Below log will be displayed if restore is done

There is a cache hit: `mykeyazureunique`
Extracting archive: 
Expected size to be downloaded: 20.7 MB
Downloaded 0.0 MB out of 20.7 MB (0%).
Downloaded 20.7 MB out of 20.7 MB (100%).
Downloaded 20.7 MB out of 20.7 MB (100%).

Then Cache location has to be communicated to target runner. In my case, I have used Maven. So I have set cache location in the Maven_opts.

MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'

Upvotes: 4

Kevin Lu-MSFT
Kevin Lu-MSFT

Reputation: 35494

I could reproduce the same issue when the docker folder is not created before the cache task.

enter image description here

You need to create the folder before the cache task or directly use the existing folder.

Here is an example:

pool:
  vmImage: windows-latest

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'New-Item -ItemType directory -Path $(Pipeline.Workspace)/docker'
- task: Cache@2
  inputs:
        key: 'docker | "$(Agent.OS)" | cache'
        path: '$(Pipeline.Workspace)/docker'

Upvotes: 1

Related Questions