Plugin for managing Ruby within Jenkins pipelines that uses rbenv under the hood. Initial work created by pedrocesar-ti which can be found here: https://github.com/pedrocesar-ti/Xenv-jenkins-lib
In some instances, it's not easy to manage ruby versions within Jenkins slaves, which is especially true with Mac slaves. As macOS comes with a system Ruby that's out of date, it's not easy to override this and have Jenkins pick it up. This plugin makes sure it uses rbenv when trying to use Ruby.
Can install with the two following ways:
You can dynamically import the library adding this snippet at the beginning of your Jenkinsfile
:
library identifier: 'withruby-lib',
retriever: modernSCM([$class: 'GitSCMSource',
remote: 'https://github.com/BenWildeman/withruby.git'])
With the Global Shared Libraries, you can import this module inside your Jenkinsfile
with the following:
@Library('withruby-lib') _
version
- specify which Ruby version to use. Default2.6.6
method
- specify whether to keep or delete the Ruby version after use. Defaultkeep
script {
withRuby() {
sh "ruby --version"
}
}
script {
withRuby("2.7.1", "delete") {
sh "ruby --version"
}
}