Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: UseRubyVersion and pipeline still uses the system ruby #4506

Closed
1 of 4 tasks
djiangnz opened this issue Nov 3, 2023 · 6 comments
Closed
1 of 4 tasks

[BUG]: UseRubyVersion and pipeline still uses the system ruby #4506

djiangnz opened this issue Nov 3, 2023 · 6 comments
Assignees

Comments

@djiangnz
Copy link

djiangnz commented Nov 3, 2023

What happened?

I expect that Ruby in the cache tool should always be used after UseRubyVersion.

  1. In capabilities, ruby is /usr/bin/ruby, bundler is /usr/local/bin/bundle
  2. I'm using rbenv. I know my env doesn't set properly but I don't think it is the root issue.
  3. UseRubyVersion
Found tool in cache: Ruby 2.7.8 x64
/usr/bin/sudo ln -sf /Users/***/_work/_tool/Ruby/2.7.8/x64/bin/ruby /usr/bin/ruby
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an 
askpass helper
sudo: a password is required
Prepending PATH environment variable with directory: /Users/***/_work/_tool/Ruby/2.7.8/x64/bin
Finishing: UseRubyVersion

the PATH is updated
4. a job in a pipeline.yml is
- bash: "./ci/bundle_install"
5. in ./ci/bundle_install
echo "$(which ruby)" # /Users/***/_work/_tool/Ruby/2.7.8/x64/bin/ruby echo "$(ruby -v)" # ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [x86_64-darwin22] bundle install --verbose

Versions

macOS: 13.6
Agent: 3.227.2

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

macos 13.6

Version controll system

No response

Relevant log output

  Resolving dependencies....
  Bundler found conflicting requirements for the Ruby version:
    In Gemfile:
      Ruby
  
      slather (= 2.7.5) was resolved to 2.7.5, which depends on
        nokogiri (>= 1.14.3) was resolved to 1.15.4, which depends on
          Ruby (>= 2.7.0)
  
  Ruby (>= 2.7.0), which is required by gem 'nokogiri (>= 1.14.3)', is not
  available in the local ruby installation
  Bundler::VersionConflict: Bundler found conflicting requirements for the Ruby version:
    In Gemfile:
      Ruby
  
      slather (= 2.7.5) was resolved to 2.7.5, which depends on
        nokogiri (>= 1.14.3) was resolved to 1.15.4, which depends on
          Ruby (>= 2.7.0)
  
  Ruby (>= 2.7.0), which is required by gem 'nokogiri (>= 1.14.3)', is not available in the local ruby installation
  /Library/Ruby/Gems/2.
  ```
@vmapetr
Copy link
Contributor

vmapetr commented Nov 7, 2023

Hi @djiangnz thank you for reporting!
Usually, such an error happens when for some reason the system Ruby location is appended after the toolcache Ruby in system PATH, however since the bundle_install stage shows the correct location the root cause is a little bit unclear.
Could you please share more details about how you use rbenv and deliver the ruby 2.7.8 to the toolcache folder?
It also may be related to the common Bundler issue - could you please check the output of which bundle before the bundle install? It should show the same path as the Ruby 2.7.8 - /Users/***/_work/_tool/Ruby/2.7.8/x64/bin/bundle

@vmapetr
Copy link
Contributor

vmapetr commented Nov 12, 2023

@djiangnz could you please check the Bundler path?

@djiangnz
Copy link
Author

djiangnz commented Nov 14, 2023

@vmapetr sorry for my late reply.

  • I have .ruby-version in my root folder
  • rbenv global is 2.7.8
  • in /Users/***/_work/_tool/Ruby/2.7.8/x64/bin, ruby is a symbol link to /Users/***/.rbenv/versions/2.7.8/bin/ruby

the path of bundler is /usr/local/bin/bundle

+ echo '🟢 Bundler version 2.1.4'
🟢 Bundler version 2.1.4

I don't have bundle in /Users/***/_work/_tool/Ruby/2.7.8/x64/bin/bundle? I assume only ruby will be picked up from here

@vmapetr
Copy link
Contributor

vmapetr commented Nov 15, 2023

Hi @djiangnz, thank you for your response!

When you use the UseRubyVersion task without changing the task's addToPath parameter, which is set to true by default, the task should append the location of the selected Ruby version from the toolcache folder to the system PATH environment variable.

On the hosted machine, it looks like this:

  - bash: |
      which ruby
      ruby --version
      which bundle

  - task: UseRubyVersion@0
    inputs:
      versionSpec: '2.7.8'

  - bash: |
      which ruby
      ruby --version
      which bundle

Default Ruby:

/usr/local/opt/[email protected]/bin/ruby
ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-darwin21]
/usr/local/lib/ruby/gems/3.0.0/bin/bundle

After UseRubyVersion:

/Users/runner/hostedtoolcache/Ruby/2.7.8/x64/bin/ruby
ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [x86_64-darwin20]
/Users/runner/hostedtoolcache/Ruby/2.7.8/x64/bin/bundle

Here, on the hosted agents, the machine already has several pre-installed Ruby versions which also include the Bundler binary, and the task simply prepends the location of the selected Ruby version to the system path so when you execute bundle install system uses the Bundler which targets the Ruby version selected in the UseRubyVersion task.

However, while using the self-hosted environment, you need to prepare the required versions of Ruby and Bundler manually before executing the task.
You deliver the Ruby on the machine using rbenv, correct?
Apparently, in this case, you should also manually install the Bundler for each Ruby version that you installing via rbenv - rbenv/rbenv#285 (comment)
Could you please try it?

@djiangnz
Copy link
Author

djiangnz commented Nov 17, 2023

@vmapetr Thanks for your reply. I think I've identified the issue, and believe this is not an azure agent bug. Thanks for your help.

TL;DR:
The issue is Bundler will run on the associate Ruby, not the Ruby in the PATH.

Here is the output before adding bundler to the tool cache folder

- bash: |
    which ruby # /usr/bin/ruby
    ruby --version # ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.x86_64-darwin22]
    which bundle # /usr/local/bin/bundle

- task: UseRubyVersion@0
    inputs:
      versionSpec: '2.7.8' # Prepending PATH environment variable with directory: /Users/.../_work/_tool/Ruby/2.7.8/x64/bin

- bash: | 
    which ruby # /Users/.../_work/_tool/Ruby/2.7.8/x64/bin/ruby
    ruby --version # ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [x86_64-darwin22]
    which bundle # /usr/local/bin/bundle

After adding Bundler to the tool cache

....
- task: UseRubyVersion@0
...
- bash: | 
    which ruby # /Users/.../_work/_tool/Ruby/2.7.8/x64/bin/ruby
    ruby --version # ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [x86_64-darwin22]
    which bundle # /Users/.../_work/_tool/Ruby/2.7.8/x64/bin/bundle

@vmapetr
Copy link
Contributor

vmapetr commented Nov 17, 2023

@djiangnz Glad that I can help!
I'll close this ticket then, please feel free to reopen it in case you have additional questions.

@vmapetr vmapetr closed this as completed Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants