Deploying a Node.js App with Jenkins, Docker & Kubernetes – Full CI/CD Pipeline Explained

A well-structured CI/CD pipeline is essential for delivering Node.js applications in a scalable, repeatable, and secure way.
In this article, I break down a complete Jenkins pipeline that:
- Installs Node.js dependencies
- Builds and pushes a Docker image
- Verifies AWS CLI and configures EKS access
- Deploys the app to Kubernetes across dev, staging, and production environments
- Includes manual approval for production deployment
This guide walks through each stage line by line to demonstrate how these tools integrate in a real-world DevOps workflow.
Full Pipeline Breakdown
pipeline
pipeline {
Begins the Jenkins declarative pipeline block.
agent
agent any
Specifies that this pipeline can run on any available Jenkins agent.
options
options {
buildDiscarder logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '',
daysToKeepStr: '7',
numToKeepStr: '2'
)
}
Limits the number of saved builds to avoid disk bloat in Jenkins. Keeps builds for 7 days and retains only the 2 most recent.
tools
tools {
nodejs 'NodeJs'
}
Specifies to use a predefined Node.js tool installation configured in Jenkins (named ‘NodeJs’).
environment
environment {
dockercred = credentials('docker-hub')
awscred = credentials('aws-key')
}
Loads Docker Hub and AWS credentials securely from Jenkins’ credentials store.
Pipeline Stages
Stage: Checkout
stage('Checkout') {
steps {
checkout scmGit(
branches: [[name: '*/main']],
extensions: [],
userRemoteConfigs: [[url: 'GitHub Link']]
)
}
}
Clones the project source code from GitHub’s main branch.
Stage: Install Dependencies
stage('Install Dependencies') {
steps {
sh 'node -v'
sh 'npm -v'
sh 'npm install'
}
}
- Verifies the installed versions of Node and npm
- Installs dependencies from package.json
Stage: Docker Build & Push
stage('Docker Build & Push') {
steps {
sh 'docker -v'
sh 'docker build -t xxxx .'
sh 'echo $dockercred_PSW | docker login -u $dockercred_USR --password-stdin'
sh 'docker push xxxxx:latest'
}
}
Builds the Docker image and pushes it to Docker Hub using credentials.
Stage: Verify AWS CLI
stage('Verify AWS CLI') {
steps {
sh 'aws --version'
sh 'aws sts get-caller-identity'
}
}
Checks AWS CLI installation and verifies the identity via STS to ensure credentials work.
Stage: Configure Kubeconfig
stage('Configure Kubeconfig') {
steps {
sh 'aws eks update-kubeconfig --region us-east-1 --name devops-working'
}
}
Updates the kubeconfig file so that kubectl commands target the specified EKS cluster.
Stage: Deploy to Dev
stage('Deploy to Dev') {
steps {
sh 'kubectl apply -f deployment-dev.yaml -n dev'
}
}
Deploys the application to the dev namespace in Kubernetes.
Stage: Deploy to Staging
stage('Deploy to Staging') {
steps {
sh 'kubectl apply -f deployment-staging.yaml -n staging'
}
}
Deploys the application to the staging namespace for pre-production testing.
Stage: Deploy to Production
stage('Deploy to Production') {
steps {
script {
def approval = input(
id: 'prod-deploy',
message: 'Approve deployment to production?',
submitter: 'admin'
)
}
sh 'kubectl apply -f deployment-prod.yaml -n prod'
}
}
Before deploying to production, this stage prompts for manual approval. Once approved, it applies the deployment manifest to the prod namespace.
Part of a Series
This article is part of a series on building real-world CI/CD pipelines for different application stacks:
- PHP Version – Composer, Docker, AWS, and Kubernetes
- Python Version – pip, Docker, AWS, and Kubernetes
- Node.js Version – this article
Final Thoughts
This Jenkins pipeline provides a practical, production-ready method for automating the build and deployment process of a Node.js application. It demonstrates how modern DevOps tools like Docker, AWS, and Kubernetes can work together to support scalable, cloud-native delivery.
Feel free to check out the full repo here 👉 GitHub Link