Connecting to GitHub

Updated on 23 Sep 2020

Create a new Project

Let’s create a new Jenkins project, and we’ll call it myDeployHub. This will be a normal FreeStyle project, and once again we’ll create a deployment folder with the appropriate permissions for the user Jenkins, just as we did in setting up a project

Notice here that we didn’t tick the GitHub box. This is optional, and when it is ticked we get additional options in the Build triggers section (i.e. build from git push).

Source Code Management - https

In the source code management section, we’ll select Git as our repository and enter our URL.

We have two choices for the URL. Either https or ssh. ssh requires that port 22 is open on our PC, and the library has it shut so we’ll stick with https for now.

Add Credentials - https

Because we are connecting to a private repo, we need to supply credentials. In our case it will be a username/password.

Once we have clicked Add, make sure that we specify our new credentials in the drop-down box.

Checking our connection

Without doing anything else we can check to make sure that our credentials and connection to gitHub are okay. Click the Build Now (or Run option if in Blue Ocean).

If everything is okay, then we’ll get a green tick.

And in the log file (by clicking on the row) we can see that we are indeed connecting to gitHub and retrieving files.

To doubly make sure that things are working the way that we expect them to, we can check the workspace.


You might need to be the Jenkins user to gain access to this directory.

sudo su jenkins

Source Code Management - ssh

SSH requires the use of port 22, which on our State Library computers has been blocked. But we can still see how to use ssh and a deploy certificate.

Create SSH key

First step is to create an SSH key for the jenkins user.

sudo su jenkins

This will create 2 files in .ssh directory of the jenkins home directory (/var/lib/jenkins).

Use the contents of and take that to your github repo. Open your repo and click the Settings button.

Click the link for Deploy keys in the left hand navigation, and then the Add deploy key button.

Copy and paste your public key into the Key field, provide an appropriate name and click the Add Key button. That’s all we need to create the ssh key, and add it to gitHub.

Add Credentials - ssh

We can add our SSH credentials in the Source Code Management section. For the URL, select the ssh link for the GitHub repo

We need to add our ssh key, so add the credentials.

Once we have clicked Add, make sure that we specify our new credentials in the drop-down box.

Unfortunately this is as far as we can go with this section because our computer is locked down and we wont be able to connect to github via ssh (port 22).