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/

相关文章:

git push origin 在总消息后挂起

git - Hudson构建因Git存储库和Grails失败

go - 在没有明确定义的结构的情况下插入 BigQuery

go - 在 Go 中为函数预计算简单值

performance - 在TeamCity中进行多次并行构建后触发一次后续构建

git - NodeJS/Jenkins/GIT 和 Jenkins Slave 作为 Web 服务器

git - 将现有项目迁移到 git

git - 为什么git要求输入 merge 消息?

go - 在 golang 中类型转换重叠结构

maven-2 - 通过 Hudson 发布 Maven