I have a small problem with Jenkins and private Github repos. To check out a private repo, one usually needs one of two things:
The deployment key was made for this kind of interaction. The problem is that deployment keys have to be unique across projects, so I'd have to use a different key every time.
This means that I'd have to add another key to the ssh-agent for the Jenkins user for every additional repo.
This also means that by default, the agent would try all of the available keys and would probably get the connection dropped after a few bad attempts with a wrong key.
The Jenkins git plugin doesn't seem to allow pointing it at an SSH key. Jenkins doesn't allow any commandline interaction before the checkout, so I can't use any bash tricks to set the correct key.
So far the only solution seems to be:
Any alternative suggestions?
Step 1: go to your GitHub repository and click on 'Settings'. Step 2: Click on Webhooks and then click on 'Add webhook'. Step 3: In the 'Payload URL' field, paste your Jenkins environment URL. At the end of this URL add /github-webhook/.
When you add a a new Pipeline job, selecting Pipeline script from SCM displays a form which allows you to select the repository from which the jenkinsfile for the pipeline is loaded. However, it also allows you to add multiple repositories, and each repository added requires its own jenkinsfile.
On GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings. In the "Access" section of the sidebar, click Collaborators & teams. Click Invite a collaborator.
This isn't exactly an answer, just an echo in the dark to let you know that I do pretty much the same thing.
jenkins
sudo
as this user and create a public ssh keymyorg-machines
jenkins
user's public ssh key to the myorg-machines
account keys on GitHub. I name this key jenkins on server.name.com
to keep things organized.Machines - Pull only
. Add the myorg-machines
GitHub user to that team, and give that team pull access to my appropriate private repos.I agree it seems klunky, but it's actually been pretty easy to manage over a year or so now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With