Breaking change to circle ci containers? - Ruby version always defaults to system ruby

Hi Guys,

We’ve recently experienced an issue with our CircleCI deployment pipeline, which has caused me pain for 3 and a half days trying to fix it.

It appears the virtual Circle CI machine running our deployment suddenly stopped using the ruby version installed in the build flow, but rather kept defaulting to the system ruby version which is outdated and therefore wouldn’t allow me to install gems correctly.

I have now implemented a fix for this problem, (using external libraries rbenv and chruby to overwrite the ruby version the shell uses) and added some checks in case the problem occurs in the future. This fix is quite non-trivial and requires alteration of the circle shells bash profile which I never have had to do before.

Was there a release on or around Monday 5th Nov 2018 which has caused this? The only thing I can see which has changed in that time is fastlane released a new gem, but this surely isn’t the cause of this problem. I have below attached our old and new build pipelines for reference.

Please do let me know if I can provide anything else and I look forward to the response. - James

Old:

deploy_ios_dev:
    macos:
      xcode: "9.0"
    environment:
      # Sets locale to UTF-8 from https://docs.fastlane.tools/getting-started/ios/setup/#set-up-environment-variables
      LC_ALL: en_US.UTF-8
      LANG: en_US.UTF-8
    working_directory: ~/repo
    steps:
      - checkout
      - attach_workspace:
          at: ~/repo
      - run: brew update
      - run: brew install ruby
      -run: sudo gem install fastlane -v 2.89.0
      # Ovewrite .env.production with .env.dev
      # - run: mv .env.dev .env.production
      # Build and deploy dev version of iOS app
      - run: npm run deploy-ios-dev

New (solution):

deploy_ios_dev:
    macos:
      xcode: "9.0"
    # Shell command necessary or bash scripts below fail
    shell: /bin/bash --login -eo pipefail
    environment:
      # Sets locale to UTF-8 from https://docs.fastlane.tools/getting-started/ios/setup/#set-up-environment-variables
      LC_ALL: en_US.UTF-8
      LANG: en_US.UTF-8
    working_directory: ~/repo
    steps:
      - checkout
      - attach_workspace:
          at: ~/repo
      - run: brew update
      # Download & install rbenv and chruby
      - run: brew install rbenv ruby-build
      - run: brew install chruby
      - run: echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
      # Ensures correct version of ruby is used
      - run: rbenv install 2.5.3
      - run: echo "ruby-2.5.3" > ~/.ruby-version
      - run: which ruby
      - run: ruby -v
      # SSL check
      - run: ruby -ropen-uri -e 'eval open("https://git.io/vQhWq").read'
      # Install fastlane
      - run: sudo gem install fastlane -v 2.89
      - run: fastlane env
      # Ovewrite .env.production with .env.dev
      # - run: mv .env.dev .env.production
      # Build and deploy dev version of iOS app
      - run: npm run deploy-ios-dev

I ran into the same issue in my Jenkins env in Mac trying to run Android fastlane, and I had to do similar workaround so it does not pick up the system ruby version. (Circleci is my main CI system and Jenkins is my backup. )

1 Like

I am unfamiliar with OS X on CircleCI. I wonder, when the environment is spinning up (in the first step), does it give you an exact version of the OS image? I also wonder whether the brew update might have caused Ruby to have behaved differently (and so it would be a Brew issue rather than an OS X or CircleCI problem).

Hi all! We did remove the Xcode 9.0.0 version and are pointing it to the 9.0.1 image. To resolve this, you can set the Ruby version with the following:

version: 2
jobs:
  build:
    macos:
      xcode: 9.0.1
    # Using chruby requires a login shell
    shell: /bin/bash --login -eo pipefail 
    steps:
      - checkout
      - run:
          name: Set Ruby Version
          command:  echo "ruby-2.4" > ~/.ruby-version
      - run: ruby -v
      - run: xcodebuild -version
1 Like