I'm getting this error every time I run a build through my azure devops pipeline:

The given cache key has changed in its resolved value between restore and save steps

I am trying to cache the cocoapods used in my react native project. I am using the hash of the Podfile.lock in the cache key string (if there are changes in the Podfile.lock then the cache key will change and a new cache will be uploaded after a cache miss)

locally if I delete the Podfile.lock and ios/Pods folder and then run a pod install nothing changes. When the build pipeline runs pod install the Podfile.lock hash does change which means that the cache can never be retrieved because the key is always being modified.

I have tried:

  • changing vmImage to 10.14 instead of macOS-latest
  • made sure that locally all pods are up to date
  • made sure that cocoapods versions are the same locally and in the build pipeline

I can't think of what else to try, there are no examples for cocoapods caching in the microsoft docs and no one seems to have run into this same problem

2

There are 2 answers

5
Cece Dong - MSFT On

The error indicates you need to make sure none of your build steps between the Cache and Post-Job Cache step change the cache key value. You may either remove the change causing step or remove Podfile.lock from the key.

2
aleksander_si On

You may try the following approach:

# Podfile.lock and project.pbxproj are changed during the build process, so we make copies
- script: |
   cp ./ios/Podfile.lock ./ios/podfile_key
   cp ./ios/AwesomeProject.xcodeproj/project.pbxproj ./ios/project_key
  displayName: Create pod cache keys

- task: Cache@2
  inputs:
    key: 'pods | "$(Agent.OS)" | ./ios/podfile_key | ./ios/Podfile | ./ios/AwesomeProject.xcworkspace/contents.xcworkspacedata | ./ios/project_key'
    path: './ios/Pods'
    cacheHitVar: 'PODS_CACHE_RESTORED'
  displayName: Cache pods

- task: CocoaPods@0
  displayName: 'pod install using the CocoaPods task with defaults'
  condition: ne(variables.PODS_CACHE_RESTORED, 'true')
  inputs:
   workingDirectory: './ios/'
   forceRepoUpdate: false