Pipeline is using wrong Ruby version

Hello,

We are using the hosted version of Gitlab and are suddenly getting the error:

Your Ruby version is 3.1.2, but your Gemfile specified 3.1.1

Our local Ruby version is 3.1.1p18

Gemfile:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
require 'net/http'
require 'json'

ruby "3.1.1"
gem 'rails',                       '7.0.2'

etc.

Gemfile.lock:

RUBY VERSION
   ruby 3.1.1p18

BUNDLED WITH
   2.3.8

gitlab-ci.yml:

stages:
    - test
    - deploy

cache:
  paths:
    - vendor/bundle
    - node_modules


test-job:
    stage: test
    image: ruby:3.1
    services:
      - postgres:12.7
    variables:
      POSTGRES_USER: depot_postgresql
      POSTGRES_PASSWORD: depot_postgresql
      DB_USERNAME: depot_postgresql
      DB_PASSWORD: depot_postgresql
      DB_HOST: postgres
      RAILS_ENV: test
      CONTACT_FORM_SENDER: "test-sender@gmail.com"
      DEFAULT_FROM_EMAIL: "test-sender@gmail.com"
      CONTACT_FORM_RECEIVER: "test-receiver@gmail.com"
      
    script:
      - apt-get update
      - apt-get --assume-yes install sudo
      - sudo apt install curl
      - curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
      - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
      - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
      - sudo apt update
      - sudo apt install nodejs
      - npm install yarn -g
      - node -v
      - npm -v
      - yarn -v
      - gem install bundler -v 2.3.8
      - bundle install
      - ruby -v
      - bundle version
      - rails -v
      - rails db:create db:schema:load --trace
      - yarn
      - rake assets:precompile
      - printenv
      - rails test

deploy_staging:
  stage: deploy

etc.

Relevant log information:

Running with gitlab-runner 14.9.0~beta.68.g1283960c (1283960c)
[2](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L2) on green-3.shared.runners-manager.gitlab.com/default Jhc_Jxvh
[3](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L3)Preparing the "docker+machine" executor00:49
[4](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L4)Using Docker executor with image ruby:3.1 ...
[5](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L5)Starting service postgres:12.7 ...
[6](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L6)Pulling docker image postgres:12.7 ...
[7](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L7)Using docker image sha256:0f698a6badfa74ce8a84a7c5b593348578bb7d348447df63f91b0d0413353615 for postgres:12.7 with digest postgres@sha256:1ba4e7aa3db644e8f6faee085bb40c1e050baa9a28f79948daa98220b2dc0394 ...
[8](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L8)Waiting for services to be up and running...
[9](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L9)Pulling docker image ruby:3.1 ...
[10](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L10)Using docker image sha256:9652d0b40707c16270c23d6b063f1bf5d27ea5aab5c363387b43651255a260fb for ruby:3.1 with digest ruby@sha256:be4f8b9043d2cc620dff313c4ea987536778f30964c333f8ca0ed3fb6402e701



$ gem install bundler -v 2.3.8
[145](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L145)Successfully installed bundler-2.3.8
[146](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L146)1 gem installed
[147](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L147)$ bundle install
[148](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L148)Your Ruby version is 3.1.2, but your Gemfile specified 3.1.1
[150](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L150)Cleaning up project directory and file based variables00:01
[152](https://gitlab.com/goandgit/saverd/-/jobs/2331815795#L152)ERROR: Job failed: exit code 1

Anyone have any ideas?

I think you can probably just change your CI config to:

test-job:
    stage: test
    image: ruby:3.1.1
    services:
      - postgres:12.7
...

Thank you snim2. That worked. I also upgrade bundler to 2.3.11 in case anyone comes across this and gives it a try but the image was most likely the main issue.

Thanks again.

1 Like