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?
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.)