为 Github 私有存储库验证 Jenkins CI [英] Authenticate Jenkins CI for Github private repository

查看:37
本文介绍了为 Github 私有存储库验证 Jenkins CI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 Jenkins 从我托管在 Github 上的私人存储库中自动获取数据.但我不知道如何完成该任务.. 尝试文档,为 jenkins 用户生成 ssh-key,我能看到的所有内容是:无法克隆 repo".我已经检查过网址 - 它们是有效的.

I'd like for Jenkins to automagically fetch data from my private repository hosted on Github. But I have no idea how to accomplish that task.. Tried the documentation, generating ssh-key for jenkins user and all what I can see is: "unable to clone the repo". I've checked URLs - they are valid.

任何线索,也许您知道一些描述此类内容的文档/博客/任何内容?

Any clues, maybe you know some docs/blogs/whatever which are describing this kind of stuff?

推荐答案

也许 GitHub 对 的支持部署密钥是你要找的吗?引用该页面:

Perhaps GitHub's support for deploy keys is what you're looking for? To quote that page:

我应该什么时候使用部署密钥?

简单,当您的服务器需要对单个私有存储库进行拉取访问时.此密钥直接附加到存储库而不是个人用户帐户.

Simple, when you have a server that needs pull access to a single private repo. This key is attached directly to the repository instead of to a personal user account.

如果这是您已经尝试过的方法但它不起作用,您可能需要使用所使用的 URL、密钥文件的名称和位置等的更多详细信息来更新您的问题.

If that's what you're already trying and it doesn't work, you might want to update your question with more details of the URLs being used, the names and location of the key files, etc.

现在是技术部分:如何在 Jenkins 中使用您的 SSH 密钥?

Now for the technical part: How to use your SSH key with Jenkins?

如果您有一个 jenkins unix 用户,您可以将您的部署密钥存储在 ~/.ssh/id_rsa 中.当 Jenkins 尝试通过 ssh 克隆存储库时,它会尝试使用该密钥.

If you have, say, a jenkins unix user, you can store your deploy key in ~/.ssh/id_rsa. When Jenkins tries to clone the repo via ssh, it will try to use that key.

在某些设置中,您无法以自己的用户帐户运行 Jenkins,也可能无法使用默认的 ssh 密钥位置 ~/.ssh/id_rsa.在这种情况下,您可以在不同的位置创建一个密钥,例如~/.ssh/deploy_key,并配置 ssh 以将其与 ~/.ssh/config 中的条目一起使用:

In some setups, you cannot run Jenkins as an own user account, and possibly also cannot use the default ssh key location ~/.ssh/id_rsa. In such cases, you can create a key in a different location, e.g. ~/.ssh/deploy_key, and configure ssh to use that with an entry in ~/.ssh/config:

Host github-deploy-myproject
    HostName       github.com
    User           git
    IdentityFile   ~/.ssh/deploy_key
    IdentitiesOnly yes

因为您使用 git@github.com 对所有 Github 存储库进行身份验证,并且您不希望将上述密钥用于与 Github 的所有连接,所以我们创建了一个主机别名 github-deploy-myproject.你的克隆 URL 现在变成了

Because all you authenticate to all Github repositories using git@github.com and you don't want the above key to be used for all your connections to Github, we created a host alias github-deploy-myproject. Your clone URL now becomes

git clone github-deploy-myproject:myuser/myproject

这也是您将存储库 URL 放入 Jenkins 中的内容.

and that is also what you put as repository URL into Jenkins.

(请注意,您必须不要ssh:// 放在前面才能使其正常工作.)

(Note that you must not put ssh:// in front in order for this to work.)

这篇关于为 Github 私有存储库验证 Jenkins CI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆