0

我正在努力解决 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": {
        ...
     }
}
4

1 回答 1

0

经过调查,调用命令的步骤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'
于 2022-02-09T20:11:02.590 回答