How to cache cocopods for CI

I am having hard time to caching pods for iOS project. I have tried few options and its not working and not clear instruction on GitLab doc as well.

This does not work.
- bundle exec pod check || bundle exec pod install

Can anyone help hear to cache pod and it should only reinstall when PodFile.lock updates.

Hi @nitinkumar.piparava

This will only work if you’ve set up caching in your .gitlab-ci.yml file.

I don’t use Cocopods, but this is the sort of thing you might use for Ruby gems:

myjob:
    ...
    cache:
        key:
            files:
                - Gemfile.lock
        paths:
            - vendor/bundle
    ...

@snim2 Thanks for quick update, Below is my yml file, You correct about bundle I am doing same thing, However with iOS pod installation every time consume 4 to 5 mins. There is no guide how we can cache that.

build_project:
  stage: build
  cache:
    key:
      files:
        - yarn.lock
    paths:
      - .yarn-cache/
    key:
       files:
         - cd ios && Podfile.lock
    paths:
      - .pod-cache/
    key:
       files:
         - Gemfile.lock
    paths:
      - vendor/ruby
    
     
  #TODO use a propper tags like: chronext, macos, macos26, xcode, xcode15, fastline, fastline45 and not this useless "beta beta-build beta-deploy beta-deployment prod prod-deploy production production-build production-deployment"
  tags:
    - beta-deployment
    - beta-build
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
      when: always
    - if: '$CI_COMMIT_BRANCH == "feature/gitlab-ci"'
      when: always
    - when: never

  script:
    - cd .. && yarn install --cache-folder .yarn-cache
    - cd ios && gem install bundler
    - bundle install --path=vendor
    - pod install
    - bundle exec fastlane beta

I think the above is most likely your problem. The paths key here must be a list of paths, so you can’t use BASH commands in that value. I think you likely want:

build_project:
  stage: build
  cache:
    key:
      files:
        - yarn.lock
    paths:
      - .yarn-cache/
    key:
       files:
         - ios/Podfile.lock
    paths:
      - .pod-cache/

But I don’t know whether .pod-cache/ is in your project root or whether you mean ios/.pod-cache here.

@snim2 Ok I got your point still it is not working and not sure how to point cache folder for pod installcommand like bundle install --path=vendor even this does not work, How can we do same with pods?

It seems GItLab has very outdated document and really do not update CI document at all. I tried below and followed exact instructions in below screenshot and still cache does not work for bundle install as well.

Error for bundle install --path=vendor

So, as I say, I don’t use Cocoapods, but their documentation suggests you should be caching ~/.cocoapods and ~/Library/Caches/CocoaPods. There’s a bit more detail on that page…