Google Cloud Build 无法拉取私有Go模块:SSH配置正常仍报仓库访问错误
GCP Cloud Build 私有Go模块拉取故障
问题背景
- 完成SSH访问链路配置:新生成SSH密钥对,将私钥存储在GCP项目的Secret Manager中,公钥配置到对应GitHub仓库的Deploy Key中,全程按照Google Cloud Build访问私有GitHub仓库的官方教程操作无异常。
- 构建执行过程中基础连通性验证通过:可以正常克隆目标代码仓库。
运行时报错
执行go get命令拉取私有依赖仓库时,构建步骤返回如下错误:
Step #2: go: github.com/felix/private-repo@<version-nr>: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /go/pkg/mod/cache/vcs/e61704280b96667bd155fe2e6c284d9506853b470d6786a1dff7011776527149: exit status 128: Step #2: ERROR: Repository not found. Step #2: fatal: Could not read from remote repository. Step #2: Step #2: Please make sure you have the correct access rights Step #2: and the repository exists. Finished Step #2
当前配置清单
cloudbuild.yaml 配置
steps: - name: 'gcr.io/cloud-builders/git' secretEnv: ['SSH_KEY'] entrypoint: 'bash' args: - -c - | echo "$$SSH_KEY" >> /root/.ssh/id_rsa chmod 400 /root/.ssh/id_rsa git config --global url."git@github.com:myOrg".insteadOf https://github.com/myOrg volumes: - name: 'ssh' path: /root/.ssh - name: 'git' path: /root/.gitconfig - name: 'golang' args: ['make', 'review'] volumes: - name: 'ssh' path: /root/.ssh - name: 'git' path: /root/.gitconfig availableSecrets: secretManager: - versionName: projects/my-project/secrets/ssh-private-key/versions/latest env: 'SSH_KEY'
Go 环境变量配置
GOPRIVATE=github.com/myOrg/* GO111MODULE=on
问题现象
- SSH基础配置已生效,能够完成目标代码仓库克隆操作
- 拉取私有Go依赖的操作始终报错,无法正常完成依赖拉取,需要排查问题根源。
内容的提问来源于stack exchange,提问作者mrfr
相关产品推荐
相关产品推荐

