CircleCIの設定で詰まった

今日は新しく覚えることがたくさん出てきましたw

 

その中でも、CircleCIの設定でかなりつまずきました。。。

なので忘れないように書き残しておこうと思います!!

 

 

どんなエラーで詰まっていたか

以下のエラーが出ており、ずっとCircleCIが落ちていました。

$ #!/bin/bash -eo pipefail
mkdir /tmp/test-results
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"

bundle exec rspec --format progress \
                --format RspecJunitFormatter \
                --out /tmp/test-results/rspec.xml \
                --format progress \
                $TEST_FILES
Requested historical based timing, but they are not present.  Falling back to name based sorting
bundler: failed to load command: rspec (/home/circleci/repo/vendor/bundle/ruby/2.6.0/bin/rspec)
LoadError: cannot load such file -- rspec_junit_formatter
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/formatters.rb:231:in `require'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/formatters.rb:231:in `rescue in custom_formatter'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/formatters.rb:228:in `custom_formatter'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/formatters.rb:181:in `find_formatter'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/formatters.rb:150:in `add'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:942:in `add_formatter'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/configuration_options.rb:118:in `block in load_formatters_into'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/configuration_options.rb:118:in `each'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/configuration_options.rb:118:in `load_formatters_into'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/configuration_options.rb:24:in `configure'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:127:in `configure'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:97:in `setup'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:86:in `run'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:71:in `run'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:45:in `invoke'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-core-3.8.0/exe/rspec:4:in `<top (required)>'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/bin/rspec:23:in `load'
  /home/circleci/repo/vendor/bundle/ruby/2.6.0/bin/rspec:23:in `<top (required)>'
Exited with code 1

 

 

解決方法

赤文字部分を削除したら無事CircleCIが通ってくれました!!

bundle exec rspec--format progress \
                --format RspecJunitFormatter \     #ここを消した
                --out /tmp/test-results/rspec.xml \
                --format progress \
                $TEST_FILES
 

 

 

以下は参考にさせていただいた記事です。

qiita.com

 

 

.circle/config.yml完成形

# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2


jobs:
build:
docker:
# specify the version you desire here
- image: circleci/ruby:2.6.1-node-browsers
environment:
RAILS_ENV: test
PGHOST: 127.0.0.1
PGUSER: root

- image: circleci/postgres:10.4-alpine
environment:
POSTGRES_USER: root
POSTGRES_DB: circle-test_test
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4

working_directory: ~/repo

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
# fallback to using the latest cache if no exact match is found
- 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" }}

# Database setup
- run: bundle exec rake db:create
- run: bundle exec rake db:schema:load


# run tests!
- 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

# collect reports
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
destination: test-results

 

 

 

感想

CircleCI & yamlというよく分からないものが重なり、とても苦戦しました。。。

結局何十回も試しては失敗をして、結局自分では解決できず、先輩に教えていただきました。

明日はfeature specのコードを書き進めていこうと思います!!