简体   繁体   English

如何在circleCI中设置ruby版本?

[英]How to set the ruby version in circleCI?

I am using circleCI for CI with the following .yml file 我正在使用circleCI for CI和以下.yml文件

version: 2
jobs:
  build:
    machine:
      ruby:
        version: 2.4.4
    steps:
      - checkout
      - run: bundle install
      - run: echo "hello"

The error message is 错误消息是

Your Ruby version is 2.3.3, but your Gemfile specified 2.4.4
Your Ruby version is 2.3.3, but your Gemfile specified 2.4.4

My Gemfile is 我的Gemfile是

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

ruby '2.4.4'

What is the proper way to set ruby version? 设置ruby版本的正确方法是什么?

It looks like you are using CircleCI 2 but you're setting the ruby version using the CircleCI 1 way. 看起来您正在使用CircleCI 2但是您正在使用CircleCI 1方式设置ruby版本。

As stated in this documentation , to set the ruby version in Circle CI 2 , you can either create a .ruby-version file in your rails app and commit the file or you can create it from a build step: 如本文档所述 ,要在Circle CI 2设置ruby版本,您可以在rails应用程序中创建.ruby-version文件并提交文件,也可以从构建步骤创建它:

run:
  name: Set Ruby Version
  command:  echo "ruby-2.4.4" > ~/.ruby-version

disclaimer: I'm a CircleCI Developer Advocate 免责声明:我是CircleCI开发者倡导者

Your config example is mixing CircleCI 2.0 and 1.0 config syntax and this is causing the issue. 您的配置示例混合使用CircleCI 2.0和1.0配置语法,这导致了问题。

If you want to use Ruby 2.4.4 in a CircleCI 2.0 build and you want to use our premade Docker image, then your config should look like this: 如果你想在CircleCI 2.0版本中使用Ruby 2.4.4并且你想使用我们预制的Docker镜像,那么你的配置应如下所示:

version: 2
jobs:
  build:
    docker:
      - image: circleci/ruby:2.4.4
    steps:
      - checkout
      - run: bundle install
      - run: echo "hello"

The above example is for the Linux environment. 以上示例适用于Linux环境。 If you're doing macOS builds, then @e_a_o's answer will help you there. 如果您正在进行macOS构建,那么@ e_a_o的答案将帮助您。

I referred this CircleCI docs and created a file .ruby-version that explicitly stated the version to be used ie 2.4.4 and it works. 我引用了这个CircleCI文档,并创建了一个文件.ruby-version,明确说明了要使用的版本,即2.4.4,它可以工作。 The content was 内容是

2.4.4 2.4.4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM