Perhaps GitHub's support for deploy keys is what you're looking for? To quote that page:
When should I use a deploy key?
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.
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.
Now for the technical part: How to use your SSH key with Jenkins?
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.
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
Because all you authenticate to all Github repositories using [email protected]
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
and that is also what you put as repository URL into Jenkins.
(Note that you must not put ssh:// in front in order for this to work.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…