Complete Jenkins CI/CD Project

Aryan KaleAryan Kale
3 min read

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 -

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.

-- 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.

🔹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

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! 📘

0
Subscribe to my newsletter

Read articles from Aryan Kale directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aryan Kale
Aryan Kale

Hi, I am Aryan Kale, a Java Backend Developer, passionate about developing production-ready applications while building and working with teams of Software Developers, aspiring to become a Technical Architect.After developing Applications in a product based startup and a mid-size service-based firm, I gained experience in Java, Python, SQL, DevOps, Docker, AWS, Leadership Skills, and Soft skills.Getting the responsibility of working with a team of enthusiastic software developers was one of the biggest achievements which improved my communication skills.I believe continuous learning and development to keep myself up to date and up-skilled is the solution to the modern-day application development for customers. Reach out to get modern-day solution for your dream project. Thank You...