git - 来自私有(private) git 存储库的 Golang 和依赖项

标签 git go continuous-integration

假设我有一个 Go 项目,它依赖于来自 github 的 2 个不同的私有(private)存储库。我正在使用部署 key 进行 github 身份验证。我正在尝试设置 CI 来构建、测试和部署整个事情。
CI 创建了所有 2 个部署 ssh key 的环境(我们称它们为 ~/.ssh/key1~/.ssh/key2)
当我运行 go build ,它会尝试一次下载所有依赖项。如何避免 repo 不存在的异常(由于身份验证问题)?你会如何解决这个问题?

最佳答案

如果您使用两个不同的键,则需要修改这些依赖项的 URL 以引用这些单独的键。
这是通过 ~/.ssh/config 完成的。 (假设 Jenkins 代理由正确的用户运行,并且确实可以访问 ~/.ssh/config在那~/.ssh/config ,您声明两个“主机”条目,每个条目都引用自己的私钥:

Host repo1
  User git
  Hostname git.server.com
  IdentityFile ~/.ssh/key1

Host repo2
  User git
  Hostname git.server.com
  IdentityFile ~/.ssh/key2
然后确保 repo1 的依赖项不再是 git@git.server.com:aUser/aRepo 而是:
repo1:aUser/aRepo

关于git - 来自私有(private) git 存储库的 Golang 和依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66008776/

相关文章:

eclipse - 无法在 Eclipse 中获取远程存储库引用

git - 如何列出已推送到远程的分支?

git - 如何创建依赖于托管在 gitlab 子组中的私有(private) go 包的 docker 镜像?

sql-server - GORM 和 SQL Server : auto-incrementation does not work

java - Travis-ci 忽略 gradle 的缓存设置

continuous-integration - 是否应该在每次构建时执行代码覆盖率?

eclipse - 无法通过SSH将裸Git项目导入Eclipse

amazon-web-services - 如何在上传开始和完成时收到通知

c - 如何将数组作为参数列表传递给 C 中具有不同数量参数的函数

amazon-web-services - 使用 AWS CodeBuild 构建 React Native