【问题标题】:tar: could not chdir to 'D:\a\1\docker'焦油:无法 chdir 到 'D:\a\1\docker'
【发布时间】:2021-10-26 17:05:14
【问题描述】:

我正在尝试使用 Azure Pipelines 中的 Cache 任务进行 Docker 设置。根据documentation我需要设置以下参数:

  • 密钥(必需)
  • 路径(必填)
  • RestoreKeys(可选)
 - task: Cache@2
      inputs:
        key: 'docker | "$(Agent.OS)" | cache'
        path: '$(Pipeline.Workspace)/docker'

很遗憾,缓存 任务的后期作业总是因此错误而失败。有什么建议吗?

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
  

更新:根据建议的答案对创建方向进行更改后,缓存已被命中,但其大小为 0.0MB。我们需要自己处理副本吗?

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




  

【问题讨论】:

  • 这个目录存在吗?就像它是否曾经在您的管道中创建或从回购中克隆? $(Pipeline.Workspace)/docker。请分享更多您的管道和文件夹结构。
  • 该文件夹不存在,我认为 CacheTask 会这样做。我们是否也需要将复制命令写入该文件夹,否则 CacheTask 会将 docker 图像复制到该文件夹​​。@TheFool

标签: docker azure-devops azure-pipelines docker-build azure-caching


【解决方案1】:

如果在缓存任务之前没有创建 docker 文件夹,我可以重现同样的问题。

需要在缓存任务前创建文件夹或直接使用已有文件夹。

这是一个例子:

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'

【讨论】:

  • 谢谢,知道这非常有用。我的印象是 CopyTask 会处理它,这可能主要是权限问题。现在,我可以看到缓存已被命中,但它的大小为 0.0MB。我们也需要自己复制吗?请参阅更新以获取更多信息。 @kevin-lu-msft
  • 根据我的测试,我没有做复制操作,它可以缓存有效的图像
  • 您使用的是自托管代理吗?
  • 没有。我使用 Microsoft 托管的代理。您的意思是您使用的是自托管代理?
  • 不,我在某处读到缓存仅适用于自托管代理。我正在使用 Microsoft 托管代理。当您说“我没有执行复制操作,它可以缓存有效图像”时,即使没有复制任务,您也使用缓存图像连续构建?如果我们没有指定,它怎么知道要缓存什么以及复制到哪里?
【解决方案2】:

我遇到了同样的问题。缓存任务前创建缓存路径文件夹后,错误解决。

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

如前所述,缓存本身仍然没有按预期工作。我将缓存文件夹、缓存键和缓存路径修改为不同的值,因为缓存是不可变的。并且 Cache key 和 restoreKeys 设置为相同的值。

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

注意:只有在作业成功时才会设置缓存。

如果缓存保存成功,那么您将在 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

现在缓存设置正确,我们必须确保在执行时获取缓存位置。首先,验证缓存是否已正确恢复。如果还原完成,将显示以下日志

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%).

然后缓存位置必须传达给目标跑步者。就我而言,我使用了 Maven。所以我在 Maven_opts 中设置了缓存位置。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-15
    相关资源
    最近更新 更多