Series: From Code to Cloud: Building a Production-Ready .NET Application
By: Farrukh Rehman - Senior .NET Full Stack Developer / Team Lead
LinkedIn: https://linkedin.com/in/farrukh-rehman
GitHub: https://github.com/farrukh1212cs
Source Code Backend : https://github.com/farrukh1212cs/ECommerce-Backend.git
Source Code Frontend : https://github.com/farrukh1212cs/ECommerce-Frontend.git
🎯 Introduction
In modern software development, manual builds and deployments are no longer sustainable. Teams need speed, reliability, and consistency. This is exactly what Continuous Integration (CI) and Continuous Deployment (CD) provide.
Jenkins is one of the most powerful tools for implementing CI/CD. It enables teams to automate everything from code integration to production deployment.
In this lecture, you will learn:
- What CI/CD really means in practice
- How Jenkins works
- How to write pipelines using Jenkinsfile
- How to automate build, test, and deployment
- Best practices used in professional teams
- This is a practical, industry-aligned guide.
What is Continuous Integration (CI)?
Continuous Integration is the practice of frequently merging code into a shared repository and automatically validating every change.
A typical CI workflow:
- Developer pushes code to GitHub
- Pipeline automatically triggers
- Application builds
- Tests run
- Feedback is provided immediately
Why CI Matters
- Bugs are caught early
- Integration conflicts are reduced
- Code quality improves
- Teams ship faster with confidence
Without CI, teams often discover problems too late — during release.
What is Continuous Deployment (CD)?
Continuous Deployment goes one step further.
After code passes:
- Build
- Tests
- Quality checks
…it is automatically deployed to environments like staging or production.
Some teams use:
- Continuous Delivery → Deployment requires manual approval
- Continuous Deployment → Deployment is fully automatic
Both models are common in professional environments.
What is Jenkins?
Jenkins is an open-source automation server that allows you to build complete CI/CD pipelines.
With Jenkins, you can:
- Pull code from repositories
- Build applications
- Run automated tests
- Perform static code analysis
- Deploy applications
- Trigger workflows across tools
Jenkins is popular because:
- It is free and open-source
- It supports thousands of plugins
- It works with almost any tech stack
- It scales from small teams to large enterprises
Jenkins Architecture (Simplified)
Jenkins typically consists of:
Jenkins Controller (Master)
- Manages jobs
- Provides UI
- Schedules pipelines
- Handles configuration
Jenkins Agents (Workers)
- Execute the actual builds
- Can run on separate machines
- Useful for scaling pipelines
Pipelines
- Define the automation workflow
- Written as code using a Jenkinsfile
Lets Write our Jenkinsfile
for backend .net application
pipeline {
agent any
options {
disableConcurrentBuilds()
}
stages {
stage('Build') {
steps {
script {
// Remove previous image with the <none> tag testing
sh 'docker rmi ecom-backend:latest || true'
// Build the new image with an explicit tag
sh 'docker build --no-cache -t ecom-backend:latest -f ECommerce.API/Dockerfile .'
// Remove dangling images
sh 'docker images -q --filter "dangling=true" | xargs docker rmi || true'
// Clean up intermediate images
sh 'docker image prune -f'
// Custom cleanup script to remove any remaining <none> tagged images
sh '''
for image_id in $(docker images --filter "dangling=true" -q); do
docker rmi $image_id || true
done
'''
}
}
}
stage('Push and Deploy') {
steps {
script {
// Stop and remove the container if it exists
sh 'docker stop ecom-backend || true'
sh 'docker rm ecom-backend || true'
// Run the new container
sh 'docker run -d --restart always --name ecom-backend --env "ASPNETCORE_ENVIRONMENT=Development" --network zohan -p 8202:8080 ecom-backend:latest'
sh 'docker image prune -f'
}
}
}
}
}
Lets Write for Frontend
pipeline {
agent any
options {
disableConcurrentBuilds()
}
stages {
stage('Build') {
steps {
sh 'docker build --no-cache -t ecom-front/ui -f Dockerfile .'
}
}
stage('Push and Deploy') {
steps {
sh 'docker stop ecom-front || true && docker rm ecom-front || true'
sh 'docker run -d --restart always --name ecom-front --network zohan -p 9201:80 ecom-front/ui:latest'
}
}
}
}
Now time to Work on Jenkin
New Item
For Frontend do same process , just update the Repo URL and branch.
Next Lecture Preview
Lecture 12 : Structured Logging & Monitoring
Configuring Serilog with Seq or ELK Stack for centralized structured logging and observability.








Top comments (0)