Setting Up a Jenkins CI/CD Pipeline for Multi-Environment Deployment (DEV,QA,PROD)

"Hello, I'm Kiran Pawar, a passionate Cloud and Devops Engineer with a strong background in cloud automation, configuration, and deployment. My journey in the world of technology has been a thrilling adventure, where I've had the privilege to work with cutting-edge tools and practices.
🚀 As a DevOps Engineer:
I specialize in automating, configuring, and deploying instances in cloud environments and data centers. My expertise extends to DevOps, GitOps, CI/CD pipeline management, HashiCorp Terraform, and containerization. I'm proficient in AWS and Linux/Unix administration, ensuring robust infrastructure and application performance.
🔧 My Tech Stack:
Front-end skills: HTML, CSS, SCSS, Tailwind CSS, Bootstrap, React, Material-UI, JavaScript DevOps toolbox: GIT, OWASP,Nexus,Trivy, Github, Gitlab, Terraform, Ansible, Docker, Kubernetes, Helm, Jenkins, Prometheus, Grafana, Argo CD, AWS EKS.
🌐 My Cloud Expertise:
I have hands-on experience managing AWS services, including EC2, S3, EBS, VPC, ELB, RDS, IAM, Route53, and more.
🔒 Networking and Security:
My skills include managing networking concepts such as TCP/IP protocols, security policies, and subnet interfacing. I have a strong understanding of infrastructure and networking, covering topics like firewalls, IP addressing, DNS, and more.
💡 What Sets Me Apart:
I bring a positive attitude, a strong work ethic, and a collaborative spirit to every project. I'm a self-starter, a fast learner, and an effective team player with strong interpersonal skills. In addition to my DevOps skills, I've developed shell scripts (Bash) for automating tasks and have proficiency in Python scripting. My ability to communicate and manage projects, along with a track record of resolving client issues, adds value to every team I work with. If you're looking for a DevOps engineer who is also well-versed in front-end technologies, feel free to connect with me. Let's explore new possibilities and create exceptional technical solutions together!"
Introduction
In modern DevOps workflows, Continuous Integration and Continuous Deployment (CI/CD) pipelines streamline software delivery, ensuring rapid and reliable deployments across multiple environments. This blog will guide you through setting up a Jenkins-based CI/CD pipeline that automates deployments to Development (Dev), Quality Assurance (QA), and Production (Prod) environments using GitHub, Jenkins, and Tomcat servers.
Prerequisites
Before diving into the setup, ensure you have:
AWS Instances running Ubuntu or any Linux distribution for hosting Jenkins and Tomcat servers.
Recommended system requirements:
Jenkins server configurations
t2.medium
15GB Disk Space
Apache tomcat server configuration (DEV,QA,PROD)
t2.micro
10GB Disk Space

Java Installation (JDK 11 or Later) on (Jenkins,DEV,QA,PROD)
Jenkins Installed on your AWS jenkins instance.
Tomcat Servers configured for Dev, QA, and Prod environments.
GitHub Repository containing the source code.
DNS Configuration using AWS Route 53 (or another DNS service) to map domains for each environment.
CI/CD Pipeline Architecture
The pipeline follows a branch-based deployment strategy:
Feature Branches → Deployed to Dev
Develop Branch → Deployed to QA
Master Branch → Deployed to Production (with approval and Slack notifications)
Step-by-Step Implementation
1. Install and Configure Jenkins

Run the following commands on your Jenkins instance to install Jenkins:
jenkins server should have jdk and maven installed
sudo apt update && sudo apt install fontconfig openjdk-17-jre maven -y
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update -y
sudo apt-get install jenkins -y
sudo systemctl enable jenkins
sudo systemctl status jenkins

Copy jenkins server public IP and Open port 8080

Retrieve jenkins default password



2. Apache Tomcat 9 Installation on DEV,QA,PROD Servers

Tomcat require Java. Install OpenJDK 11 using:
sudo apt update && sudo apt install fontconfig openjdk-17-jre -y

Download and install Apache Tomcat 9:
wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.99/bin/apache-tomcat-9.0.99.tar.gz
tar -xvf apache-tomcat-9.0.99.tar.gz

Modify the configuration files:
cd apache-tomcat-9.0.99/webapps/manager/META-INF
vim context.xml

Remove line <Valve>

After removed you’ll see something like this

Save context.xml
Add users for Tomcat Manager:
cd apache-tomcat-9.0.99/conf/tomcat-users.xml
vim tomcat-users.xml

Add below lines
<role rolename="manager-gui"/>' >> tomcat-users.xml
<role rolename="manager-script"/>' >> tomcat-users.xml
<user username="admin" password="admin" roles="manager-gui,manager-script"/>

Start the Tomcat server:
cd apache-tomcat-9.0.99/bin
./startup.sh

Copy DEV server public IP and paste into the browser

Access Tomcat via: http://your-server-ip:8080

Go to Manager App and login using username and password of tomcat user

Do these steps for both QA and PROD servers and install Apache Tomcat
3. Install Necessary Plugins
Navigate to Manage Jenkins → Manage Plugins.

Install Git parameter Plugin, Pipeline Stage view Plugin, Slack Notification Plugin..

4. Configure Slack Credentials
Open slack APP>Create channel name cricket

Click More>Automations>Apps.
search for jenkins App

Add to slack

Select channel to integrate slack with jenkins

Read points to configure secrets in jenkins

Copy workspace and secret token generated by slack
Go to manage jenkins>system>slack.

Generate slack token
click Add and create credentials in jenkins for slack

Save credentials

5. Create jenkins CICD job
Click on New Item

Create Pipeline named CICD-JOB





Create a Jenkinsfile in your GitHub repository:
pipeline {
agent any
parameters {
string(name: 'BRANCH_NAME', defaultValue: '', description: 'Specify the branch name to deploy')
}
stages {
stage("GIT checkout") {
steps {
script {
// Checkout the specified branch
def branchName = params.BRANCH_NAME
checkout([$class: 'GitSCM', branches: [[name: branchName]], userRemoteConfigs: [[url: 'https://github.com/imkiran13/boxfuse-java-maven-app.git']]])
}
}
}
stage("Testing") {
steps {
echo "Test Runs"
}
}
stage("Build") {
steps {
sh "mvn clean package"
sh "mv target/hello-1.0.war target/boxfuse-java-maven-app.war"
}
}
stage("Deploy to Dev") {
when {
expression { params.BRANCH_NAME == 'dev' }
}
steps {
deployToTomcat('65.2.161.227', 'admin', 'admin', 'http://65.2.161.227:8080/manager/text', '/boxfuse-java-maven-app', 'Dev')
}
}
stage("Deploy to QA") {
when {
expression { params.BRANCH_NAME == 'qa' }
}
steps {
deployToTomcat('15.207.16.116', 'admin', 'admin', 'http://15.207.16.116:8080/manager/text', '/boxfuse-java-maven-app', 'QA')
}
}
stage("Deploy to Prod") {
when {
expression { params.BRANCH_NAME == 'main' }
}
steps {
input(message: "Do you want to proceed to PROD?", ok: "Proceed") // Approval step
// Deploy to PROD server after approval
deployToTomcat('43.204.103.54', 'admin', 'admin', 'http://43.204.103.54:8080/manager/text', '/boxfuse-java-maven-app', 'Prod')
// Send Slack notification
slackSend(channel: 'cricket', message: "Deployment to PROD has been approved by manager.")
}
}
}
}
def deployToTomcat(tomcatIP, username, password, tomcatURL, contextPath, environment) {
def warFileName = 'target/boxfuse-java-maven-app.war'
// Deploy the WAR file using curl
sh """
curl -v -u ${username}:${password} --upload-file ${warFileName} ${tomcatURL}/deploy?path=${contextPath}&update=true
"""
echo "Deployment to ${environment} server completed."
}
6.Create Dev and QA branches in the Repository




Create one more branch for QA


Successfully created qa and dev branches from main branch
Go to VSCODE and git fetch from repository

This will fetch dev and qa branch to the local that we created on remote location ie. on repository
Now we can checkout to dev and qa branches

we can see all 3 branches are available on our local .
7. Trigger and Monitor the Pipeline
Push code changes to different branches and observe the deployment process.
Monitor the Jenkins console output for logs and errors.
Trigger dev pipeline



trigger qa pipeline



Trigger Prod pipeline


We need to manually approve deployment to prod environment


8.Slack Notification of Pipeline approval

Conclusion
By following these steps, you’ve successfully set up a Jenkins CI/CD pipeline for seamless deployments across Dev, QA, and Prod environments. This setup ensures automated testing, approval-based production releases, and Slack notifications for deployment status updates.
Stay tuned for more DevOps tutorials!
