Troubleshooting for Ruby gems

This document explains why certain errors may occur when working with Ruby gems in an Artifact Registry repository, and possible remedies for those situations.

Expired push credentials

You made a push request but received the following error message:

Pushing gem to https://LOCATION-ruby.pkg.devPROJECT/REPOSITORY..
The request does not have valid authentication credentials.

To refresh your credentials, generate a new token by running the following command:

export GEM_HOST_API_KEY="Bearer $(gcloud auth print-access-token)"
export HOST="https://LOCATION-ruby.pkg.dev/PROJECT/REPOSITORY"
bundle config $HOST $GEM_HOST_API_KEY

Where:

  • LOCATION is the regional or multi-regional location for the repository.
  • PROJECT is the project ID. If this flag is omitted, then the current or default project is used.
  • REPOSITORY is the ID of the repository. If you configured a default Artifact Registry repository, then that default repository is used when this flag is omitted from the command.

Login prompt when pushing

You made a push request but received received a message requesting your ruby.pkg.dev credentials:

Enter your https://us-ruby.pkg.dev/REPOSITORY/GEM_NAME credentials.
Don't have an account yet? Create one at https://us-ruby.pkg.dev/REPOSITORY/GEM_NAME/sign_up
   Email:

Try running the following:

GEM_HOST_API_KEY="Bearer $(gcloud auth print-access-token)"

Expired pull credentials

You made a pull request but received the following error message:

 Unable to download data from https://oauth2accesstoken:REDACTED@LOCATION-ruby.pkg.dev/PROJECT/REPOSITORY/ - bad response Unauthorized 401 (https://oauth2accesstoken:REDACTED@LOCATION-ruby.pkg.dev/PROJECT/REPOSITORY/latest_specs.4.8.gz)

To refresh your credentials, remove the expired credential source from gem sources. Next, generate a new token by running the following command:

export GEM_HOST_API_KEY="Bearer $(gcloud auth print-access-token)"
export HOST="https://LOCATION-ruby.pkg.dev/PROJECT/REPOSITORY"
bundle config $HOST $GEM_HOST_API_KEY

Where:

  • LOCATION is the location of your repository.
  • PROJECT is the project ID. If this flag is omitted, then the current or default project is used.
  • REPOSITORY is the name of your repository in Artifact Registry.

Pull request error: Could not fetch specs

You made a pull request but received the following error message:

Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch specs from https://LOCATION-ruby.pkg.dev/PROJECT/REPOSITORY/ due to underlying error <bad response Not Found 404 (https://LOCATION-ruby.pkg.dev/PROJECT/REPOSITORY/specs.4.8.gz)>

This error may incorrectly appear even though the pull request was successful. Use a verbose command to verify that your pull request succeeded, such as bundle install --verbose.