Skip to content

Instantly share code, notes, and snippets.

@pete911
Last active December 31, 2020 00:39
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pete911/6219918 to your computer and use it in GitHub Desktop.
Save pete911/6219918 to your computer and use it in GitHub Desktop.
jenkins with private github projects
- login to jenkins box (ssh)
- switch user to jenkins "sudo su -s /bin/bash jenkins"
- go to jenkins home directory "cd ~"
- generate keys (you need separate pair per github private project as the projects are on the same domain)
- "ssh-keygen -t rsa -f ~/.ssh/id_rsa_<project>" (replace <project> with your project name)
- repeat this for every github project
- crate "config" file in .ssh dir - "vim ~/.ssh/config" with the following content:
# <project1>
Host github.com-<project1>
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_<project1>
# <project2>
Host github.com-<project2>
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_pbs_<project2>
- replace occurences of <project1> and <project2> with the actual projects (in comment, Host and IndentityFile)
add more projects if necessary
- get public key for a project "cat ~/.ssh/id_rsa_<project>.pub" (replace <project> with your project)
- copy the key and paste it in github project under settings -> deploy keys
- test config file:
"ssh git@github.com-<project1>" (replace <project1> with the actual project)
- the above is required as it adds entry to your allowed hosts file, otherwise jenkins would fail as it
doesn't answer 'yes' to adding entry to known hosts
- go to jenkins UI and change "Repository URL" under "Git" to "git@github.com-<project>:<user>/<project>.git" (replace <project> and <user>)
- try to build the job
- to setup a trigger, I found that the easiest way to do it is to use "WebHook URL" in github (under settings -> service hooks)
"http://<jenins>/job/<job_name>/build?token=<random_security_token>
- then in jenkins UI go to job, add Trigger builds remotely under Build Triggers and add the same random_authentication_token
- go back to github and click test hook, if the job starts building then it's DONE
@okryvorotko
Copy link

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment