Node-todo-CI/CD deploy using jenkins

Node-todo-CI/CD deploy using jenkins

First you Create ec2 Instance :

then go to instance and do ssh :

after you install jenkins but after jenkins you first install JAVA

so go to this link : https://www.jenkins.io/doc/book/installing/linux/

and copy the command and paste it in your shell

after that you install jenkins

sudo apt-get install docker.io

Add Jenkins User to Docker Group

sudo usermod -aG docker jenkins

docker --version

Enable and Start Docker :

sudo systemctl enable docker

sudo systemctl start docker

and allow port 8080 in your inbound rule security group :

copy public ip:8080

13.61.33.32:8080

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

and copy the password and paste it

and then continue

then install suggested plugins

fill this and after that save and continue

then save and finish

Go to manage jenkins then plugins :

after that available plugin and install the pipeline plugins :

After that restart jenkins :

jenkins is ready and start using jenkins

Welcome to Jenkins Dashoard 😊❤️

then go to new item

and then go to pipeline then ok

copy project url

after that go to pipline and write the script

pipeline { agent any stages { stage("Clone Code") { steps { git url: 'https://github.com/LondheShubham153/node-todo-cicd.git', branch: 'master' } }

stage("Build Code") { steps { sh "whoami" // Build Docker image with the correct name sh "docker build -t node-todo-app ." } }

stage("Deploy") { steps { // Stop any running container with the same name (optional) sh "docker rm -f node-todo-app || true"

// Run the container with the correct image and container name sh "docker run -d -p 8000:8000 --name node-todo-app node-todo-app" } } } }

apply save and then build now

sudo docker ps

http://52.15.209.33:8000/todo

(using webhook)

what is a webhook?

Webhooks are user-defined HTTP callbacks (or small code snippets linked to a web application) which are triggered by specific events.

example :-If there is any code push or any changes on GitHub, then he pushes those changes in Jenkins.

First, you create a webhook

step 1:

go to your GitHub :

step :2 Go to repo

step :3 go to repo setting and then webhook and add webhook

copy jenkins ip address and paste it on payload

and then add webhook

go to jenkins dashboard and then configuration :

click on GitHub hook trigger for GITScm polling

apply and save

to check go to github and then views and edit something what you want :

automatic build