Azure Devops:给定的缓存键在还原和保存步骤之间的解析值发生了变化;

Azure Devops: The given cache key has changed in its resolved value between restore and save steps;

我正在努力应对 Azure Devops 中显示的一个警告。

##[warning]The given cache key has changed in its resolved value between restore and save steps;
original key: npm|"Linux"|1hQ5erTp1F2VHRtmwbSGxyt5NqLK6CNbXboa/qqfKiE=
modified key: npm|"Linux"|ckttYS61PMovYKX4+92Nb7dvktCebx236/7P4XqXK6Q=

我不知道 yaml 文件中的哪一步仍然会触及 package-lock.json

DevOps 使用以下版本的 nodejs 和 npm

Found tool in cache: node 16.13.2 x64
/opt/hostedtoolcache/node/16.13.2/x64/bin/npm --version
8.1.2

我的机器

node -v
v16.13.1
npm -v
8.3.0

有什么想法吗?

谢谢

Yaml

trigger:
- master
- develop
- features/*
- hotfix/*

pool:
  vmImage: ubuntu-latest
variables:
  NPM_CONFIG_CACHE: $(Pipeline.Workspace)/.npm
  disable.coverage.autogenerate: 'true'

steps:
- task: gitversion/setup@0
  displayName: "Setup Git versioning"
  inputs:
    versionSpec: '5.x'

- task: gitversion/execute@0
  displayName: "Execute Git versioning"
  inputs:
    useConfigFile: true
    configFilePath: 'GitVersion.yml'

- script: |
    echo '##vso[task.setvariable variable=buildVersion]$(GitVersion.FullSemVer)'
  displayName: 'Set build version variable'
 
- task: NodeTool@0
  displayName: 'Install Node.js'
  inputs:
    versionSpec: '16.x'

- task: Cache@2
  displayName: 'Restore NPM cache'
  inputs:
    key: 'npm | "$(Agent.OS)" | package-lock.json'
    restoreKeys: |
       npm | "$(Agent.OS)"
    path: $(NPM_CONFIG_CACHE)

- task: Npm@1
  displayName: 'NPM install'
  inputs:
    command: 'custom'
    customCommand: 'ci'

- task: Npm@1
  displayName: 'Lint'
  inputs:
    command: 'custom'
    workingDir: '$(Build.SourcesDirectory)'
    customCommand: 'run lint'

- task: Npm@1
  displayName: 'Build'
  inputs:
    command: 'custom'
    workingDir: '$(Build.SourcesDirectory)'
    customCommand: 'run build'

- task: Npm@1
  displayName: "Run unit tests"
  inputs:
    command: 'custom'
    workingDir: '$(Build.SourcesDirectory)'
    customCommand: 'run test:ci'

- task: Npm@1
  inputs:
    command: 'custom'
    workingDir: '$(Build.SourcesDirectory)'
    customCommand: 'version $(buildVersion) --no-git-tag-version'
  displayName: "Add version"

- task: Npm@1
  displayName: 'Publish to feed'
  inputs:
    command: 'publish'
    publishRegistry: 'useFeed'
    publishFeed: 'c63597a4-6555-4a12-a8dd-0a2a5a0fefe3/afac8330-979d-45e8-a168-8c0a2ed47ac4'

包-lock.json

{
    "name": "test",
    "version": "0.1.0",
    "lockfileVersion": 2,
    "requires": true,
    "packages": {
        ...
     }
}

经过调查,调用命令 npm version $(buildVersion) --no-git-tag-version 的步骤是触摸 package-lock.json

我在 Publish to feed

之后添加了重置版本的额外步骤
- task: Npm@1
  displayName: 'Reset version'
  inputs:
    command: 'custom'
    workingDir: '$(Build.SourcesDirectory)'
    customCommand: 'version 0.1.0 --no-git-tag-version'