简体   繁体   中英

gitlab CI - installing correct version of yarn

I'm trying to set up CI/CD using gitlab and I'm stuck at specific moment. Below is my .gitlab-ci.yml file:

image: "ruby:2.6"

before_script:
  - ruby -v
  - apt-get update -qy
  - apt-get install -y nodejs
  - apt-get install -y yarn
  - yarn --version
  - bundle install --path /cache
  - bundle exec rails webpacker:install

test:
  script:
    - bundle exec rake db:create RAILS_ENV=test
    - bundle exec rake test

The CI output progresses without an error until it hits $ bundle exec rails webpacker:install . Task is aborted with this message:

$ bundle exec rails webpacker:install
rails aborted!
ArgumentError: Malformed version number string 0.32+git
/builds/kvinklly/sample-app/bin/rails:5:in `<top (required)>'
/builds/kvinklly/sample-app/bin/spring:8:in `require'
/builds/kvinklly/sample-app/bin/spring:8:in `block in <top (required)>'
/builds/kvinklly/sample-app/bin/spring:5:in `tap'
/builds/kvinklly/sample-app/bin/spring:5:in `<top (required)>'
Tasks: TOP => webpacker:install => webpacker:check_yarn
(See full trace by running task with --trace)

I noticed that the 0.32+git value is most likely the version of yarn that gets installed, and verified that is the version:

$ yarn --version
0.32+git

Is there a way to specify a newer version or the latest version of yarn during a CI script on gitlab?

I can post the gemfile, but it's a fairly basic rails app without much added at this point.

I got it to work using the following:

# Official language image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/ruby/tags/
image: "ruby:2.6"

# This is a basic example for a gem or script which doesn't use
# services such as redis or postgres
before_script:
  - ruby -v  # Print out ruby version for debugging
  - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
  - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
  - apt-get update -qy
  - apt-get install -y nodejs
  - apt-get install -y yarn
  - yarn install --check-files
  - bundle install --path /cache  # Install dependencies into ./vendor/ruby
  - bundle exec rake webpacker:install

test:
  stage: test
  script:
    - bundle exec rake db:create RAILS_ENV=test
    - bundle exec rake test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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