Day-3: Complete Jenkins CI/CD Project
Let's create a comprehensive CI/CD pipeline for ourNode.js application! 😍

Did you finish Day 2?
Day 2 focused on Jenkins CI/CD, ensuring you understood the basics. Today, you'll take it a step further by completing a full project from start to finish, which you can proudly add to your resume.
As you've already worked with Docker and Docker Compose, you'll be integrating these tools into a live project.
Task 1 & Task2
project guidelines
Fork this repository for todo-cicd app & set up a connection between your Jenkins job and your GitHub repository through GitHub Integration (GitHub WebHooks).
Learn about GitHub Webhooks and ensure you have the CI/CD setup configured.
In the "Execute Shell" section of your Jenkins job, run the application using Docker Compose.
Create a Docker Compose file for this project (a valuable open-source contribution).
node-todo-cicd Project
Edit inbound rules of Agent server to add node-todo-app port
Follow the path mentioned below for the same.
EC2 \> Security Groups > sg-00585ab3cb6b573e3 - launch-wizard-1 > Edit inbound rules
add 8000
Edit inbound rules of Master server to add Jenkins port
Follow the path mentioned below for the same.
EC2 \> Security Groups > sg-00585ab3cb6b573e3 - launch-wizard-1 > Edit inbound rules
add 8080

now to access Jenkins open a new tab > master_server_public_ip:8080
Jenkins URL: http://52.89.79.80:8080/ (Here 52.89.79.80 is public IP of your instance)
Now, go to the Jenkins Dashboard and click on New Item.

Name: todo-CICD
select Pipeline > OK

Description:
GitHub Project > Project URL: Paste the HTTPS code of your forked directory into the GitHub Project URL field.

Advance > Display Name: node-todo-app CICD
Pipeline > Definition > Pipeline script
Script
pipeline {
agent{
node{
label "dev"
}
}
stages{
stage("clone code"){
steps{
git url: "https://github.com/Anju9358/node-todo-cicd.git", branch: "master"
echo "code clone is done"
}
}
stage("Build & Test"){
steps{
sh "docker build -t todo-app:latest ."
echo "Build process is done through docker"
}
}
stage("Deploy"){
steps{
sh "docker compose up -d"
echo "Deploymet is done"
}
}
}
}
SAVE

Build Now

Go to the last build history to check the console output and pipeline overview.

Build is successful.
Jenkins node-todo-app is ready :)
open a new tab > public_ip:8000

Jenkins to-do app is functioning correctly.
Webhooks Steup on GitHub
Setting up a connection between Jenkins and GitHub involves configuring GitHub Integration so that Jenkins can interact with your GitHub repositories. This setup typically includes integrating webhooks for automated build triggers and using credentials to access your repository.
Follow the path below to set up Webhooks on your GitHub.
GitHub Account > node-todo-cicd > settings > Code and automation > Webhook >add Webhook



Paylpoad URL: http://50.18.239.195:8080/github-webhook/
(here http://50.18.239.195:8080 is Jenkins URL)
SSL verification: Disabled
Which events would you like to trigger this webhook: Just the push event.
Add webhook

Webhook successfully added
Now Configure Jenkins Job for GitHub Webhooks
Jenkins Dashboard > todo CICD > Configuration

Build Triggers:
GitHub hook trigger for GITScm polling? [check]
Poll SCM [check]
save
To check if the webhook is working, make a change in the GitHub repository and you will see a new build start automatically.


Run the project and celebrate your accomplishment! 🎉
Challenges I faced while building this app and how I resolved these errors
1st Build was failed

check console output to find error

error: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post
To solve this error, we will access the agent server and grant permission using the command mentioned below.
sudo chown ubuntu /var/run/docker.sock

Now follow the same above process:)



