Skip to main content

Command Palette

Search for a command to run...

🚀Day 24 Task: Complete Jenkins CI/CD Project😃

Let's make a beautiful CI/CD Pipeline for our Node JS Application 😍

Published
4 min read
🚀Day 24 Task: Complete Jenkins CI/CD Project😃
T

As a DevOps Engineer, I'm passionate about building and maintaining robust, efficient, and scalable infrastructure to enable seamless software delivery. With a strong foundation in C/C++, Linux, and a toolkit that spans AWS, Jenkins, Docker, Nagios, Kubernetes, YAML, Ansible, Terraform, Bash Scripting, Git, and GitHub, I'm well-equipped to tackle the challenges of modern software development and deployment.

In today's fast-paced development environment, implementing robust CI/CD processes is crucial for efficient and reliable software delivery. This blog explores the integration of Jenkins, GitHub, and Docker to automate and streamline the development pipeline

Task-01:

  1. Fork Repository:
  • Go to the GitHub repository you want to use for CI/CD.

  • Click the "Fork" button in the upper right corner of the repository's page.

  • This creates a copy of the repository under your GitHub account.

    •     ubuntu@ip-172-31-5-106:~/projects$ git clone https://github.com/LondheShubham153/node-todo-cicd.git
          Cloning into 'node-todo-cicd'...
          remote: Enumerating objects: 237, done.
          remote: Counting objects: 100% (34/34), done.
          remote: Compressing objects: 100% (29/29), done.
          remote: Total 237 (delta 10), reused 21 (delta 3), pack-reused 203
          Receiving objects: 100% (237/237), 120.18 KiB | 7.51 MiB/s, done.
          Resolving deltas: 100% (93/93), done.
          ubuntu@ip-172-31-5-106:~/projects$ ls
          node-todo-cicdConnect Jenkins with GitHub:
      
  1. Create a connection to your Jenkins job and your GitHub Repository via GitHub Integration.

    We can use SSH keys or PAT tokens to integrate the GitHub repo into Jenkins.

    Here I am using SSH keys.

    1. Generate SSH key pair in your Jenkins instance.
    ubuntu@ip-172-31-5-106:~/projects/node-todo-cicd$ 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
    The key fingerprint is:
    SHA256:FQiGg1v4+eVJKcK74Jk3fwYrIx/HK2kwkP7RtkKvO/M ubuntu@ip-172-31-5-106

2. Create a new SSH key in GitHub and save the public key of Jenkins Instance.

No alt text provided for this image

No alt text provided for this image

3. Save the Private key in Jenkins credential.

No alt text provided for this image

No alt text provided for this image

4. Create a new Freestyle Jenkins Job -

No alt text provided for this image

5. Add source code GitHub Repo with added credential -

No alt text provided for this image

6. Now run the pipeline to check if the source code is checked out through Jenkins -

No alt text provided for this image

The repo files are present in Jenkins Workspace -

7. Now we need to set up a webhook for an automatic trigger from GitHub.

-- Install the GitHub integration plugin in Jenkins.

No alt text provided for this image

-- Create a Webhook.

The payload URL should be in the below format

http://jenkins_URL/github-webhook/

No alt text provided for this image

8. Do not forget to open port 8080 to Anywhere so that the GitHub webhook can reach Jenkins on port 8080.

The green tick shows that the connection is established.

No alt text provided for this image

9. In your Jenkins Job, enable GitHub Hook to trigger in the build trigger section.

No alt text provided for this image

10. To test the webhook, make some changes to the code and commit it.

Check if the Job was triggered by a push event.

No alt text provided for this image

🔹Step 3

In the Execute shell run the application using Docker compose.

  1. Create a Dockerfile to install all the dependencies and containerize the application.

No alt text provided for this image

2. Add a build step - Execute shell to build the docker image.

No alt text provided for this image

3. Docker image is created successfully.

No alt text provided for this image

No alt text provided for this image

4. Create a docker-compose file to run the container using this image.

No alt text provided for this image

5. Add the docker-compose up command to run the container.

No alt text provided for this image

6. The build is successful.

No alt text provided for this image

7. The container is up and running.

8. Since I want to run the application on Port 8100, I made changes in the app.js file.

No alt text provided for this image

9. Now my application is running.

No alt text provided for this image


Thank You for Reading! 📘

90DaysOfDevOps

Part 23 of 50

This repository is a Challenge for the DevOps Community to get stronger in DevOps. This challenge starts on the 22nd octobe 2023 and in the next 90 Days we promise ourselves to become better at DevOps

Up next

🚀Day 25 Task: Complete Jenkins CI/CD Project - Continued with Documentation😃

Continuously Integrate and Deploy a NodeJS Application using Jenkins

More from this blog

Trushid's blog

90 posts

Proficient in DevOps, Cloud & SDLC including analysis, design. Scripting, testing, automation, version control, documentation and support