-
-
Save amenpunk/33480537b2d466c6fdb4f273f8eea0be to your computer and use it in GitHub Desktop.
jenkins with private github projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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 [email protected]<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 "[email protected]<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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment