Skip to main content

Caching Ruby Gems

Abstract

You can cache Ruby Gems by putting the Bitrise.io Cache:Push Step at the end of your Workflow. To later use this cached data, use the Bitrise.io Cache:Pull Step after Git Clone Step.

Branch-based caching vs key-based caching

This guide is is about legacy, branch-based caching. For key-based caching, check out our in-depth guide: Key-based caching.

You can read about our dedicated key-based caching Steps here: Dedicated caching Steps for dependency managers.

Ruby Gems are not cached by default on the bitrise.io virtual machines. Ruby Gems are installed into a location depending on the current rbenv version. The version can be checked by running rbenv version.

You can get the location of this directory with gem environment gemdir. However, it is not enough to cache this directory as rbenv sets up link to ruby version specific gems: the whole ruby version specific directory - for example, /Users/vagrant/.rbenv/versions/2.5.3 - has to be cached.

It is not recommended to set the value of the $GEM_HOME Enviroment Variable, as this can result in installed gems not being found.

  1. Open your app on Bitrise.

  2. Click the Workflows button on the main page.

    opening-workflow-editor.png
  3. On the Workflows & Pipelines pages, you can:

    • Click the Edit bitrise.yml button to get to the bitrise.yml tab of the Workflow Editor.

    • Select a Workflow from the list of the app's Workflows.

  4. Open the Workflow Editor.

  5. Add a Script Step to the Workflow.

  6. Set the $GEM_CACHE_PATH Environment Variable in the Script Step.

     - script:
         title: Set GEM_CACHE_PATH env var
         inputs:
         - content: |-
             #!/bin/bash
             set -ex
             RBENV_DIR="`cd $(rbenv which ruby)/../..;pwd`"
             echo "Gem cache directory: $RBENV_DIR"
             envman add --key GEM_CACHE_PATH --value $RBENV_DIR
  7. Insert the Cache:Pull Step after the Git Clone but before the Android Build Steps.

  8. Insert the Cache:Push Step to the very end of your Workflow.

  9. Open the input Cache paths of the Step Cache:Push and add $GEM_CACHE_PATH in a new line as an additional cache dir.

And you’re done!