NodeJS application deployment using Jenkins CI/CD

Hi there! I'm Ojas Jawale, a passionate Cloud, DevOps and Cyber Security enthusiast. I love to dive into the latest new technologies and sharing my journey through blog. I'm always eager to learn and grow in this ever-evolving field of DevOps and Cyber Security. You'll find me writing about CI/CD pipelines, automation, containerization with Docker, and other exciting tech topics related to software quality and deployment. My goal is to demystify complex DevOps and Cyber Security concepts, provide practical tips on automation and testing, and inspire others in the developer and operations community. Let's connect, learn, and build amazing, high-quality software together!
Architecture of Project

Setup GitHub repository for source code and CI
GitHub repository used -> node-todo
Note : If you need detailed overview you can also view this Blog.
Setup Job on Jenkins for application
Create EC2 instance for Jenkins server
Update repository packages
Create Job,


- Add basic script for testing,
pipeline{
agent any;
stages{
stage("Code"){
steps{
echo "Source code fetched........."
}
}
stage("Build"){
steps{
echo "Image created SUCCESS........."
}
}
stage("Push"){
steps{
echo "Pushing to dockerhub........."
}
}
stage("Deploy"){
steps{
echo "Deployement done........."
}
}
}
}

Setup security credentials in Jenkins
GitHub credentials
Go to, Dashboard -> Manage Jenkins -> Credentials -> System -> Global credentials -> Add Credentials

-> Go to Github.com and create Personal Access Token.


DockerHub Credentials
Go to, Dashboard -> Manage Jenkins -> Credentials -> System -> Global credentials -> Add Credentials



Setup GitHub WebHook
Go to repository -> Setting -> Webhook -> Add WebHook
Payload URL -: http://IP_of_Jenkins:8080/github-webhook/


Setup CI/CD pipeline
pipeline{
agent any;
stages{
stage("Code"){
steps{
echo "Pulling source code from GitHub...."
git url: "https://github.com/ojasjawale/node-todo-cicd.git/", branch: "master"
}
}
stage("Build"){
steps{
echo "Image building started........."
sh 'docker build -t node-app:v1 .'
echo "Image Build SUCCESS............"
}
}
stage("Push"){
steps{
withCredentials([usernamePassword(credentialsId: 'dockerhub-cred', passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
sh 'docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}'
sh 'docker image tag node-app:v1 ${DOCKER_USER}/node-app:v1'
sh 'docker push ${DOCKER_USER}/node-app:v1'
echo "Image pushed to DockerHub successfully......."
}
}
}
stage("Deploy"){
steps{
echo "Deployement In-progress........."
sh 'docker stop node-app && docker rm node-app'
sh 'docker run --name node-app -p 8000:8000 ojasjawale/node-app:v1'
echo "Deployement SUCCESS........."
}
}
}
}
- Build the Job,


- Access application,

Connect With Me
Follow me for more amazing content :)




