Skip to main content

Working with RubyGems

Publish RubyGems Package​

  1. Edit $HOME/.gem/credentials to add a source:

    ---
    https://onedev.example.com/<project path>/~rubygems: Bearer <onedev_access_token>
    ParamExplanation
    <project path>path of a project with package management enabled
    <onedev_access_token>OneDev access token with package write permission over the project
  2. Run below command to prevent the file from reading by others

    chmod 0600 $HOME/.gem/credentials
  3. Push desired gem to the source

    gem push --host https://onedev.example.com/<project path>/~rubygems /path/to/<package>-<version>.gem
    ParamExplanation
    <project path>same as above
  4. For CI/CD job, run below to add source via command step

    mkdir -p $HOME/.gem

    # Use job token to tell OneDev the build publishing the package
    # Job secret 'access-token' should be defined in project build setting as an access token with package write permission

    cat << EOF > $HOME/.gem/credentials
    ---
    https://onedev.example.com/<project path>/~rubygems: Bearer @job_token@:@secret:access-token@
    EOF

    chmod 0600 $HOME/.gem/credentials

    gem build <package>.gemspec
    gem push --host https://onedev.example.com/<project-path>/~rubygems <package>-<version>.gem
    ParamExplanation
    <project path>same as above

Consume Published RubyGems Package​

Open the package detail page for installation instructions. Use an account or token with package read permission and install from the OneDev source:

gem install <package> --version <version> --clear-sources --source https://onedev.example.com/<project-path>/~rubygems --no-document

Configure download authentication as shown on the package detail page. The bearer credential in $HOME/.gem/credentials authenticates gem push; package installation may need separate source authentication. Keep credentials out of source control.

RubyGems package linked to its CI publishing build