[CircleCI] "You must use Bundler 2 or greater with this lockfile."というエラー

CircleCIの設定を自分でも書いてみたいと思い、自分の個人アプリにCircleCIを導入しておりました。

エラーが出て少々ハマった部分があったので書いておこうと思います!

 

 

エラー内容

以下のように、bundle installを実行する部分で `You must use Bundler 2 or greater with this lockfile.` というエラーが出てしまっておりました。

$ #!/bin/bash -eo pipefail
bundle install --jobs=4 --retry=3 --path vendor/bundle
You must use Bundler 2 or greater with this lockfile.
Exited with code 20

 

 このエラーが出ていた時の設定ファイルの中身が以下です。

.crlcleci/config.yml

version: 2

jobs:
build:
docker:
- image: circleci/ruby:2.6.1-node-browsers
environment:
RAILS_ENV: test
PGHOST: 127.0.1
PGUSER: root

- image: circleci/postgres:latest
environment:
POSTGRES_USER: root
POSTGRES_DB: circle-test_test

working_directory: ~/repo

steps:
- checkout

- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
- v1-dependencies-

- run:
name: install dependencies
command: |
bundle install --jobs=4 --retry=3 --path vendor/bundle

- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}

- run: bundle exec rake db:create
- run: bundle exec rake db:schema:load

- run:
name: run tests
command: |
mkdir /tmp/test-results
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"

bundle exec rspec --format progress \
--out /tmp/test-results/rspec.xml \
--format progress \
$TEST_FILES

- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
destination: test-results

 

 

エラー原因

どうやら、CilcleCI上ではデフォルトで2系のbundlerは使えないことが原因のようでした。

 

 

解決方法

設定ファイルの中に2系のbundlerを使えるようにする設定を追加したところ、無事CIが通ってくれるようになりました!!

 

以下がCI通るようになった時の .circleci/config.ymlの中身です!

黄色い部分が変更部分です!

.circleci/config.yml

version: 2

jobs:
build:
docker:
- image: circleci/ruby:2.6.1-node-browsers
environment:
RAILS_ENV: test
PGHOST: 127.0.1
PGUSER: root
BUNDLER_VERSION: 2.0.1

- image: circleci/postgres:latest
environment:
POSTGRES_USER: root
POSTGRES_DB: circle-test_test

working_directory: ~/repo

steps:
- checkout

- run:
name: setup bundler
command: |
sudo gem update --system
sudo gem uninstall bundler
sudo rm /usr/local/bin/bundle
sudo rm /usr/local/bin/bundler
sudo gem install bundler

- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
- v1-dependencies-

- run:
name: install dependencies
command: |
bundle install --jobs=4 --retry=3 --path vendor/bundle

- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}

- run: bundle exec rake db:create
- run: bundle exec rake db:schema:load

- run:
name: run tests
command: |
mkdir /tmp/test-results
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"

bundle exec rspec --format progress \
--out /tmp/test-results/rspec.xml \
--format progress \
$TEST_FILES

- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
destination: test-results

 

 

感想その他

CI通ると嬉しいですね!!

最低限の内容しか組み込めてないので、もっと調べて試していこうと思います!