Ruby gem 问题排查

本文档介绍了在 Artifact Registry 代码库中使用 Ruby gem 时可能会出现某些错误的原因,以及针对这些情况的可能补救措施。

推送凭据已过期

您发出了推送请求,但收到了以下错误消息:

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

如需刷新凭据,请运行以下命令以生成新令牌:

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

其中:

  • LOCATION 是代码库的单区域或多区域 位置
  • PROJECT 是项目 ID。如果省略此标志,则 系统会使用当前项目或 默认项目
  • REPOSITORY 是代码库的 ID。如果您配置了 默认 Artifact Registry 代码库,则在命令中省略此标志时,系统会使用该默认代码库。

推送时出现登录提示

您发出了推送请求,但收到了要求您提供 ruby.pkg.dev 凭据的消息:

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:

请尝试运行以下命令:

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

拉取凭据已过期

您发出了拉取请求,但收到了以下错误消息:

 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)

如需刷新凭据,请从 gem sources 中移除已过期的凭据来源。接下来,运行以下命令以生成新令牌:

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

其中:

  • LOCATION 是代码库的位置。
  • PROJECT 是项目 ID。如果省略此标志,则 系统会使用当前项目或 默认项目
  • REPOSITORY 是 Artifact Registry 中代码库的名称。

拉取请求错误:Could not fetch specs

您发出了拉取请求,但收到了以下错误消息:

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)>

即使拉取请求成功,此错误也可能会错误地显示。请使用 verbose 命令验证拉取请求是否成功,例如 bundle install --verbose