If you read A small help to get you into Continuous Integration you now have a server running Jenkins and you’re ready to start doing CI. Let’s hook it up with Github.
First step is to install the necessary plugins. Let’s go over to Manage Jenkins -> Manage Plugins.
Here, click Available and type Github in the search box. Select the Github plugins.
To be sure, let’s restart Jenkins. You might need to refresh the page once it’s over.
Let’s create an example project. On the main screen click New Item. Give your project a name and select Build a free-style software project.
Go to your Github repository and on the right side select ssh and copy the URL
In Jenkins again, under Source code management select Git and paste the URL in Repository URL.
If you move the cursor to any other place you’ll notice the red error message. This one was on purpose to make you aware of the next step. What this means is that Jenkins was unable to connect to Github. We need to let Github “know” about you Jenkins server. Click Save and let’s see how to do that.
Go to the folder where whe vagrant files live and type:
$ vagrant ssh
Once your in, let’s access you jenkins user by typing:
$ sudo su – jenkins
You’re now ready to generate an ssh key. Type the following command and follow the instructions:
If you followed the default instructions, you now have a public key. Get it by typing:
$ cat .ssh/id_rsa.pub
You should see something similar to this:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCq2Asfk/kdYaBf5h4cX+BFRDEtZFnIv2tcBPklN+obUvclhEVt0n7yZ+MLsTDownSSOrPZwqxnIj0FRUJ4Hj8Hx/jZlCf7V5s3kIA+FHvHIfaBiKAhCdnqtNflHe03bO0MTciSlYcQVwAR8JYBwk/8Alr2/sR7Rbwu+05NiTJ0xb6Y54OTtYHitHqrDaHKMaJSkLRnjzMlZ3vcHpckgGyyZd8NiRNRX0XL2pDG21C+nQyGLu9GjKJh0ixxk3E5lgpvj/w4pFOxozIswpTzf6oXqaELoK3Y0zHwNvFyAgY3Thn+tWGPlD3a0OLcsNqB8Pa8XP04Bo0fRW/6L+1trLE5 jenkins@precise64
Copy your public key and go over to your Github project. On the right hand side click Settings and then Deploy Keys -> Add deploy key. In the form give a name to your key, and paste the public key you got from your Jenkins server.
Back to your shell, let’s check that we can access Github by typing (say yes when a asked):
$ ssh -T email@example.com
You should receive a message similar to:
Hi mccricardo/demo_project! You’ve successfully authenticated, but GitHub does not provide shell access.
That’s all folks. If you don’t trust me, click Configure on the left and verify that the error message disappeared. You’re now one step further into CI.