Solution
您可能需要向运行 Jenkins 的 Compute Engine 虚拟机实例添加缺失的范围,以使其能够访问 Cloud Source Repository。您可以按照文档 https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#changeserviceaccountandscopes或此步骤,您觉得方便即可。
- Go to 云部署管理器 https://pantheon.corp.google.com/dm/deployments
- 单击相关 Jenkins 部署的名称
- 单击左侧信息窗格中的实例名称,它会将您重定向到
VM instance details
-
Stop
实例
- Press
Edit
并为Cloud Source Repository设置正确的访问范围
启动 VM 实例后,尝试再次添加 git 存储库,一旦选择凭据(“来自元数据的 Google 服务帐户”或来自服务帐户),一切都应该正常工作。
阐述
我偶然发现了“无效的身份验证凭据”。部署后尝试添加云源存储库时出现问题来自 Launcher 的 Jenkins https://console.cloud.google.com/launcher/details/click-to-deploy-images/jenkins?q=jenkins.
就我而言,发生这种情况的原因是在部署过程中云API访问范围 https://cloud.google.com/compute/docs/access/service-accounts#accesscopesiam对于云源存储库在 Compute Engine 虚拟机实例上被设置为Disabled
,即使服务帐户拥有所有必要的角色/权限,也会阻止该实例的任何交互。
以下是 Launcher 重新配置的范围:
scopes:
- 'https://www.googleapis.com/auth/cloud.useraccounts.readonly'
- 'https://www.googleapis.com/auth/devstorage.read_only'
- 'https://www.googleapis.com/auth/logging.write'
- 'https://www.googleapis.com/auth/monitoring.write'
{% if enableComputeApi %}
- 'https://www.googleapis.com/auth/compute'
{% endif %}
- 'https://www.googleapis.com/auth/cloudruntimeconfig'
添加以下内容scope https://developers.google.com/identity/protocols/googlescopes#sourcerepov1运行 Jenkins 的 VM 实例足以修复错误:
https://www.googleapis.com/auth/source.read_only
Extra:
Google API 的范围列表。 https://developers.google.com/identity/protocols/googlescopes