CI/CD using Github and Jenkins

Updated 24 October 2019

In this blog we will see how to perform CI/CD using Github and Jenkins.

One of the basic steps of implementing CI/CD is integrating your SCM (Source Control Management) tool with your CI tool. This saves you time and keeps your project updated all the time. One of the most popular and valuable SCM tools is GitHub.

(Note- If you have your repository on bitbucket you can refer the following link.)

 

The integration presented in this blog post will teach you to:

  • Schedule your build
  • Pull your code and data files from your GitHub repository to your Jenkins machine
  • Automatically trigger each build on the Jenkins server, after each Commit on your Git repository.

 

For this demo, we will use the following:-

  1. Jenkins Server v2.176.3
  2. Ubuntu Server 18.04 LTS
  3. Github private repository

 

We will launch an EC2 Instance (Ubuntu 18.04LTS) from our AWS console and install apache2 on it by executing the following commands:-


 

Remote SSH Server Configuration:-

You need to add your AWS EC2 server under Jenkins.

Log in into your Jenkins server and go to Manage Jenkins-> Configure Credentials-> Credentials-> System -> Global Credentials(unrestricted)-> Add Credentials -> and select SSH Username with private key.

 

 

Now we are good to go, let’s configure the Github and Jenkins integration. Let’s begin with the GitHub side!

 

Configuring Github:-

 

Step1:- Go to your Github repository and click on ‘Settings’.

 

 

Step2:- Click on Webhooks and then click on ‘Add webhook’.

 

 

Step3:-  Configure the webhook as shown in the figure.

 

(NOTE- your URL should look like this http or https://Jenkins_server_IP or domain/github-webhhook/ )

 

We’re done with the configuration on GitHub’s side! Now let’s move on to Jenkins.

 

Configuring Jenkins:-

Step1:- In Jenkins, click on ‘New Item’ to create a new project.

 

 

Step2:- Give your project a name, then choose the ‘Freestyle project’ and finally click on ‘OK’.

 

 

Step3:- Click on the ‘Source Code Management’ tab

 

 

Step4:-  Paste your GitHub repository URL in the ‘Repository URL’ field.

 

(Note:- If you have a private repo, you need to add your credentials first in Jenkins for which you can refer the following link )

 

Step5:- Click on the ‘Build Triggers’ tab and then on the ‘GitHub hook trigger for GITScm polling’. Or, choose the trigger of your choice.

 

 

 

Step6: Under Build select execute shell script on remote host using ssh and select your ssh server credentials and under Command write the following:-


 

 

Save the job.

Now go to your main repository in Github, and perform any push/merge operation on it which will result in the following;-

  • The push/merge event will activate our webhooks which will trigger our Jenkins job
  • Our Jenkins job will ssh into our EC2 server and perform the commands specified under the step.
  • Automatically trigger each build on the Jenkins server, after each Commit on your Git repository.

 

On browsing your Apache2 server it should display the following result –

Now you have successfully Implemented CI/CD using Github and Jenkins.

 

In case of any help or query, please contact us or raise a ticket at

 [email protected].

Category(s) AWS cloud ecommerce linux
author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project






    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home