The Ops Community

Cover image for Build First Jenkins Freestyle Job and Connect With GitHub
Nurul Ramadhona
Nurul Ramadhona

Posted on • Updated on

Build First Jenkins Freestyle Job and Connect With GitHub

We already installed Jenkins and currently we can access the dashboard. The next step we would try is creating job. Besides that, we will also try to connect with GitHub and manage credential for that.

1. Create Job

  • Click Create a Job or New Item menu on the left hand side.

New Item

  • Enter the job's name and description, then click Save.

Jenkins Job 1

Jenkins Job 1.2

  • Click Build Now to execute the job. The action will be notified on Build History. If it turns green, means success.

Jenkins Job 1.3

Jenkins Job 1.4

  • We can also go to the Console Output to see what's the job currently doing.

Jenkins Job 1.5

Jenkins Job 1.6

2. Enable SSH Key
To connect with GitHub, we need to add SSH pub-key to GitHub as credential. Because our VM is newly used, let's generate new key by running:

ubuntu@ip-172-31-17-9:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ubuntu/.ssh/id_rsa
Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

Then, copy the pub-key to your GitHub account. As informed above, it's placed on /home/ubuntu/.ssh/id_rsa.pub (please define your own path if it's different with mine).

ubuntu@ip-172-31-17-9:~$ cat .ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

Jenkins Job 1.7

3. Install Plugin

  • Go to Manage Jenkins => Manage Plugins => Search the name.
  • Checklist the column => Click Download and Install

(Please remember the steps above cause we'll do same thing when we need more plugins later).

Jenkins Job 1.8

Jenkins Job 1.9

Jenkins Job 1.10

Jenkins Job 1.11

4. Manage Credentials
After we add the pub-key to GitHub. We have to setup credential for Jenkins to make it able to connect or do anything with GitHub such as pull. Why? Because when we connect a job to SCM (in this case GitHub), it'll be doing some operations such as pull the repository. So, let's make Jenkins act as a host by copying the private key.

  • Go to Manage Jenkins => Manage Credentials => Global

Jenkins Job 1.12

Jenkins Job 1.13

  • Choose SSH Username with private key, then enter your GitHub's username along with the private key.

Jenkins Job 1.14

Jenkins Job 1.15

Jenkins Job 1.16

5. Add SCM To The Job
Since we've installed the Git plugin, now the option to use Git as SCM will be shown. Just copy the repository URL and choose the newly added credential. If you don't have one, you can create new repository first.

Jenkins Job 1.17

Jenkins Job 1.18

Let's check it by running Build Now!

Jenkins Job 1.19

Jenkins Job 1.20

Jenkins Job 1.21

Alright, that's it for now! Any feedback are very welcome and thank you for coming. Follow me to get notified when new post is published by me! Thank you.

Let's continue to the next part!

Discussion (0)