Cache issues when trying to build iOS apps with parallel Jenkins pipeline builds on a single Mac machine Cache issues when trying to build iOS apps with parallel Jenkins pipeline builds on a single Mac machine jenkins jenkins

Cache issues when trying to build iOS apps with parallel Jenkins pipeline builds on a single Mac machine


I solved this problem by writing a script to manage cache of dependencies for cocoapods, gems and carthage based on different versions of Gemfile.lock, Podfile.lock & Cartfile.resolved.

Sample script in Jenkinsfile to manage cache

sh '''      set +x      mkdir -p ${HOME}/ioscache/pod      # CocoaPods      POD_SHASUM=$(shasum Podfile.lock | awk '{print $1}')      POD_KEY="pod-${POD_SHASUM}"      POD_CACHE_PATH="${HOME}/ioscache/pod/${POD_KEY}.tar.gz"      echo "Checking cache for CocoaPods with they key: $POD_KEY"      if [ ! -e "${POD_CACHE_PATH}" ]; then        echo "CocoaPods cache not found with the key: $POD_KEY"        POD_CACHE_FOUND=false      else        echo "CocoaPods cache found with the key: $POD_KEY"        echo "restoring cache.."        tar xf ${POD_CACHE_PATH}        POD_CACHE_FOUND=true      fi      make pod-install      if [ "$POD_CACHE_FOUND" = "false" ]; then        echo "Saving cache for CocoaPods with key: $POD_KEY"        tar cfz ${POD_CACHE_PATH} Pods/        echo "Saved."      fi    '''

Repeat the same for Gemfile.lock and Cartfile.resolved.


I can see that you're doing a pod install in your build script and Cocoapods is then downloading dependencies. I think that multiple instances of Cocoapods downloading dependencies simultaneously could be the cause of 2 of the 3 errors you have posted. At the very least it would definitely be slowing down your builds.

Is it feasible to check your Pods directory into git along with your source? There are pros and cons to doing this but it's a common practice, and is even recommended by Cocoapods developers. You could then potentially remove the pod install step from your build script which should speed things up significantly.