Skip to main content

Command Palette

Search for a command to run...

NodeJS application deployment using Jenkins CI/CD

Updated
2 min read
NodeJS application deployment using Jenkins CI/CD
O

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!

  1. Architecture of Project


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


  1. 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........."
            }
        }
    }    
}


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


  1. Setup GitHub WebHook

Go to repository -> Setting -> Webhook -> Add WebHook

Payload URL -: http://IP_of_Jenkins:8080/github-webhook/


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

LinkedIn | GitHub

Follow me for more amazing content :)

More from this blog

Untitled Publication

52 posts