Maven 存储库缓存:为什么在第一次运行时缓存了,但在第二次运行时出现缓存未命中?

问题描述 投票:0回答:1

我在 CI/CD 管道中遇到 Maven 存储库缓存问题,尽管在第一次运行中成功解析了缓存,但在第二次运行中似乎存在缓存未命中。因此管道会再次下载 Maven 依赖项。我错过了什么?

详情如下:

第一次运行的日志:

2024-02-16T06:07:55.0601063Z ##[section]Starting: Cache Maven local repo
2024-02-16T06:07:55.0604747Z ==============================================================================
2024-02-16T06:07:55.0604864Z Task         : Cache
2024-02-16T06:07:55.0604921Z Description  : Cache files between runs
2024-02-16T06:07:55.0604995Z Version      : 2.198.0
2024-02-16T06:07:55.0605064Z Author       : Microsoft Corporation
2024-02-16T06:07:55.0605132Z Help         : https://aka.ms/pipeline-caching-docs
2024-02-16T06:07:55.0605208Z ==============================================================================
2024-02-16T06:07:55.4414221Z Resolving key:
2024-02-16T06:07:55.4553411Z  - "funcs" [string]
2024-02-16T06:07:55.4571469Z  - maven   [string]
2024-02-16T06:07:55.4571795Z  - "Linux" [string]
2024-02-16T06:07:55.5018041Z  - pom.xml [file] --> 5893AE16A5F30361F4225A94E477DB4CD1996348660AD3CFBB1F4DBF72753257
2024-02-16T06:07:55.5064081Z Resolved to: "funcs"|maven|"Linux"|EpdW7VOO9P62oHHqI9TxsjUKX3NemXThFSh/NjDbSf8=
2024-02-16T06:07:55.5126152Z Resolving restore key:
2024-02-16T06:07:55.5126751Z  - maven   [string]
2024-02-16T06:07:55.5127024Z  - "Linux" [string]
2024-02-16T06:07:55.5133145Z Resolved to: maven|"Linux"|**
2024-02-16T06:07:55.5133337Z Resolving restore key:
2024-02-16T06:07:55.5133577Z  - maven [string]
2024-02-16T06:07:55.5133821Z Resolved to: maven|**
2024-02-16T06:07:55.5592310Z Using default max parallelism.
2024-02-16T06:07:56.4382488Z Using default max parallelism.
2024-02-16T06:07:56.4391109Z Max dedup parallelism: 192
2024-02-16T06:07:56.4391465Z DomainId: 0
2024-02-16T06:07:56.5918440Z ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session 2c5e36a2-f0aa-46fc-8d04-fce0bc3c204d
2024-02-16T06:07:56.5943617Z Hashtype: Dedup64K
2024-02-16T06:07:56.7734517Z Getting a pipeline cache artifact with one of the following fingerprints:
2024-02-16T06:07:56.7735134Z Fingerprint: `"funcs"|maven|"Linux"|EpdW7VOO9P62oHHqI9TxsjUKX3NemXThFSh/NjDbSf8=`
2024-02-16T06:07:56.7735886Z Fingerprint: `maven|"Linux"|**`
2024-02-16T06:07:56.7736226Z Fingerprint: `maven|**`
2024-02-16T06:07:57.3874838Z There is a cache miss.
2024-02-16T06:07:58.0799644Z ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session 2c5e36a2-f0aa-46fc-8d04-fce0bc3c204d
2024-02-16T06:07:58.0924753Z ##[section]Finishing: Cache Maven local repo

第二次运行的日志:

2024-02-16T06:21:28.1316213Z ##[section]Starting: Cache Maven local repo
2024-02-16T06:21:28.1319938Z ==============================================================================
2024-02-16T06:21:28.1320071Z Task         : Cache
2024-02-16T06:21:28.1320128Z Description  : Cache files between runs
2024-02-16T06:21:28.1320203Z Version      : 2.198.0
2024-02-16T06:21:28.1320263Z Author       : Microsoft Corporation
2024-02-16T06:21:28.1320345Z Help         : https://aka.ms/pipeline-caching-docs
2024-02-16T06:21:28.1320422Z ==============================================================================
2024-02-16T06:21:28.4851948Z Resolving key:
2024-02-16T06:21:28.5007633Z  - "funcs" [string]
2024-02-16T06:21:28.5025467Z  - maven   [string]
2024-02-16T06:21:28.5026109Z  - "Linux" [string]
2024-02-16T06:21:28.5434800Z  - pom.xml [file] --> 5893AE16A5F30361F4225A94E477DB4CD1996348660AD3CFBB1F4DBF72753257
2024-02-16T06:21:28.5478850Z Resolved to: "funcs"|maven|"Linux"|EpdW7VOO9P62oHHqI9TxsjUKX3NemXThFSh/NjDbSf8=
2024-02-16T06:21:28.5537145Z Resolving restore key:
2024-02-16T06:21:28.5537814Z  - maven   [string]
2024-02-16T06:21:28.5538343Z  - "Linux" [string]
2024-02-16T06:21:28.5543267Z Resolved to: maven|"Linux"|**
2024-02-16T06:21:28.5543652Z Resolving restore key:
2024-02-16T06:21:28.5544353Z  - maven [string]
2024-02-16T06:21:28.5544566Z Resolved to: maven|**
2024-02-16T06:21:28.5983821Z Using default max parallelism.
2024-02-16T06:21:29.4158957Z Using default max parallelism.
2024-02-16T06:21:29.4167148Z Max dedup parallelism: 192
2024-02-16T06:21:29.4169349Z DomainId: 0
2024-02-16T06:21:29.5509867Z ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session e570c636-2828-41f0-a57d-df6db6a4a793
2024-02-16T06:21:29.5531316Z Hashtype: Dedup64K
2024-02-16T06:21:29.8068742Z Getting a pipeline cache artifact with one of the following fingerprints:
2024-02-16T06:21:29.8069565Z Fingerprint: `"funcs"|maven|"Linux"|EpdW7VOO9P62oHHqI9TxsjUKX3NemXThFSh/NjDbSf8=`
2024-02-16T06:21:29.8070600Z Fingerprint: `maven|"Linux"|**`
2024-02-16T06:21:29.8070948Z Fingerprint: `maven|**`
2024-02-16T06:21:30.8048244Z There is a cache miss.
2024-02-16T06:21:31.6162213Z ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session e570c636-2828-41f0-a57d-df6db6a4a793
2024-02-16T06:21:31.6285835Z ##[section]Finishing: Cache Maven local repo

我的管道

trigger:
  branches:
    include:
      - "master"

variables:
  MAVEN_CACHE_FOLDER: $(MAVEN_HOME).m2/repository
  MAVEN_OPTS: "-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)"

stages:
  - stage: Build
    displayName: "CI"
    jobs:
      - job: Build
        displayName: "Build/Test Service"
        pool:
          vmImage: ubuntu-latest
        container:
          image: maven:3.9-eclipse-temurin-21
        steps:
          - checkout: self
            fetchDepth: 0

          - task: Cache@2
            displayName: "Cache Maven local repo"
            inputs:
              key: '"funcs" | maven | "$(Agent.OS)" | pom.xml'
              restoreKeys: |
                maven | "$(Agent.OS)"
                maven
              path: $(MAVEN_CACHE_FOLDER)

          - task: Maven@3
            inputs:
              mavenPomFile: "pom.xml"
              goals: "clean install"
              options: "-DskipTests $(MAVEN_OPTS)"
            displayName: "Maven Install"

更改为

$(MAVEN_HOME).m2/repository
,因为我使用的是maven:3.9-eclipse-temurin-21容器映像

java maven caching azure-devops azure-pipelines
1个回答
0
投票

在我这边测试,使用你的YAML文件时没有同样的问题。我所做的唯一更改是从密钥中删除了“pom.xml”。第一次成功运行后,我可以在日志中看到

There is a cache hit: "funcs"|maven|"Linux"

根据此文档缓存任务:它是如何工作的,在作业中的所有步骤都运行并假设成功作业状态后,会自动添加一个特殊的“作业后:缓存”步骤,并为每个“恢复”触发缓存”这一步没有被跳过。这一步负责保存缓存。请确保“Maven Install”在首次运行时成功。

© www.soinside.com 2019 - 2024. All rights reserved.