Day 24 & 25: Complete Jenkins CI/CD Project and its Documentation.

Day 24 & 25: Complete Jenkins CI/CD Project and its Documentation.

Today I have created a Completed CI/CD Pipeline for a Website from Scratch using GitHub + Docker + Jenkins + Nodejs.

This Blog also has Documentation of it for exploration of how I created it.

Let's make a beautiful CI/CD Pipeline for your Node JS Application.

What is CI/CD Pipeline?

  • CI or Continuous Integration is the practice of automating the integration of code changes from multiple developers into a single codebase. It is a software development practice where the developers commit their work frequently to the central code repository (Github or Stash). Then there are automated tools that build the newly committed code and do a code review, etc as required upon integration.

  • The key goals of Continuous Integration are to find and address bugs quicker, make the process of integrating code across a team of developers easier, improve software quality and reduce the time it takes to release new feature updates.

  • CD or Continuous Delivery is carried out after Continuous Integration to make sure that we can release new changes to our customers quickly and in an error-free way. This includes running integration and regression tests in the staging area (similar to the production environment) so that the final release is not broken in production. It ensures to automate the release process so that we have a release-ready product at all times and we can deploy our application at any point in time.


Fork from GitHub Repository


Task-01

Create a connection to your Jenkins job and your GitHub Repository via GitHub Integration.

  • Let's create a freestyle project for forked repository in which we will connect Jenkins and GitHub repository via GitHub Integration.

Forked into my Personal Account

Screenshot from 2023-04-07 19-09-54

Creation of freestyle project on Jenkins

Screenshot from 2023-04-07 19-11-24


What is GitHub Webhooks?

  • A GitHub webhook is a mechanism that allows GitHub to send a notification to an external service (such as Jenkins) when certain events occur in a GitHub repository, such as when a new commit is pushed, a pull request is opened or closed, or a new release is published.

Steps:

  • In your GitHub repository, go to "Settings" and then click on "Webhooks".

  • Click on "Add webhook" and specify the URL that GitHub should send the webhook to.

  • Select the events that should trigger the webhook. Optionally, you can add a secret key to the webhook for added security.

  • Click on "Add webhook" to save your webhook configuration.

Screenshot from 2023-04-08 13-10-21

Now Since this is our private repository we will create SSH Key Pair.

Public Key -> GitHub Profile.

Private Key -> Jenkins Profile.

So, Open Terminal:

  • ssh-keygen

Screenshot from 2023-04-08 13-18-30

  • To see what is Public Key:- cat ~/.ssh/id_rsa.pub

Screenshot from 2023-04-08 13-21-16 (1)

  • Now paste your Public Key in "Settings > SSH and GPG Keys > Create New Key > Give any name > Paste Public Key".

Screenshot from 2023-04-08 13-30-31

  • To see what is Private Key:- cat ~/.ssh/id_rsa

Screenshot from 2023-04-08 13-35-48

Now, we will paste the Private Key into Jenkins "Created_Project > Configuration > Source Code Management > Credentials > Add Jenkins > Choose SSH Private Key > Paste it".

Screenshot from 2023-04-08 13-39-18

Screenshot from 2023-04-08 13-39-47

Now we have connected everything between GitHub and Jenkins.

Let's start Project Testing On Jenkins.

Creation of freestyle project on Jenkins

Screenshot from 2023-04-07 19-11-24

  • Did the Basic Configurations in Jenkins.

Screenshot from 2023-04-07 20-26-36

Screenshot from 2023-04-07 20-26-42

  • Final Output

Screenshot from 2023-04-07 20-22-24


Task-02

Let's first build Docker Image and run it on port 8000.

docker build . -t todo-node-app
docker run -d --name node-todo-app -p 8000:8000 todo-node-app

Screenshot from 2023-04-08 00-33-10

Final Output

Screenshot from 2023-04-08 00-55-33

On localhost 8000

Screenshot from 2023-04-08 12-39-42


In the Execute shell run the application using Docker Compose Down

docker-compose down

Screenshot from 2023-04-08 12-37-57

Final Output

Screenshot from 2023-04-08 12-37-42

Since docker downed the website so there is no connection

Screenshot from 2023-04-08 12-37-34


In the Execute shell run the application using Docker Compose Up.

docker-compose up -d

Screenshot from 2023-04-08 12-39-57

Final Output

Screenshot from 2023-04-08 12-39-35

Since docker is Up we have a website connected to CI/CD Pipeline.

Screenshot from 2023-04-08 12-39-42


Happy Learning :)

Did you find this article valuable?

Support DevOps by becoming a sponsor. Any amount is appreciated!