CI/CD Concepts
Understand Continuous Integration, Continuous Delivery, and Continuous Deployment. Learn pipeline stages, automation strategies, and deployment patterns.
Understand Continuous Integration, Continuous Delivery, and Continuous Deployment. Learn pipeline stages, automation strategies, and deployment patterns. This hands-on tutorial focuses on practical implementation of ci/cd concepts concepts.
CI/CD Concepts
CI/CD (Continuous Integration/Continuous Delivery/Deployment) is the backbone of modern DevOps, enabling teams to deliver software quickly and reliably.
Understanding CI/CD
┌─────────────────────────────────────────────────────────────────┐
│ CI/CD Pipeline │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Code ──> Build ──> Test ──> Stage ──> Deploy ──> Monitor │
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ Push Compile Unit Integ. Prod. Alert │
│ Trigger Code Tests Tests Deploy Logs │
│ │ │ │
│ Security Performance │
│ Scan Tests │
│ │
│ Continuous Integration (CI) ────────>│<── Continuous Delivery │
│ │
└─────────────────────────────────────────────────────────────────┘
Continuous Integration (CI)
What is CI?
Developers frequently merge code changes to a central repository, followed by automated builds and tests.
Core Principles
- Frequent Commits: Multiple times per day
- Automated Builds: Every commit triggers a build
- Fast Feedback: Know within minutes if something breaks
- Self-Testing Builds: Automated tests verify each build
- Visible Results: Everyone sees build status
Benefits
- Early Bug Detection: Find issues before they reach production
- Reduced Integration Problems: Small, frequent merges prevent "integration hell"
- Faster Development: Less time debugging integration issues
- Higher Quality: Automated testing catches regressions
- Confidence: Reliable builds enable frequent releases
Continuous Delivery vs Continuous Deployment
Continuous Delivery (CD)
Software is automatically built, tested, and prepared for release to production.
┌─────────────────────────────────────────────────────────────────┐
│ Continuous Delivery │
├─────────────────────────────────────────────────────────────────┤
│ │
│ CI Pipeline ──> Staging ──> Manual ──> Production │
│ Success Deploy Gate Deploy │
│ Auto (Click) Auto │
│ │
│ Key: Production deployment is MANUALLY triggered │
│ │
└─────────────────────────────────────────────────────────────────┘
Characteristics:
- Automated up to production
- Manual approval for production
- Production-ready artifacts always available
- Suitable for regulated environments
Continuous Deployment (CD)
Software is automatically deployed to production after passing all tests.
┌─────────────────────────────────────────────────────────────────┐
│ Continuous Deployment │
├─────────────────────────────────────────────────────────────────┤
│ │
│ CI Pipeline ──> Staging ──> Automated ──> Production │
│ Success Deploy Tests Deploy │
│ Auto (Smoke) Auto │
│ │
│ Key: Production deployment is FULLY AUTOMATED │
│ │
└─────────────────────────────────────────────────────────────────┘
Characteristics:
- Fully automated pipeline
- No manual intervention
- Requires comprehensive testing
- Feature flags control releases
- High confidence in automated tests
Comparison
| Aspect | Continuous Delivery | Continuous Deployment |
|---|---|---|
| Production Deploy | Manual trigger | Automatic |
| Automation Level | High | Complete |
| Risk Tolerance | Lower | Higher |
| Testing Required | Good | Comprehensive |
| Use Case | Regulated industries, B2B | SaaS, consumer apps |
CI/CD Pipeline Stages
Typical Pipeline
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│ Build │──>│ Test │──>│ Stage │──>│ Deploy │──>│ Monitor │
│ │ │ │ │ │ │ │ │ │
│ Compile │ │ Unit │ │ Deploy │ │ Prod │ │ Metrics │
│ Package │ │ Integ. │ │ to │ │ Deploy │ │ Logs │
│ │ │ Security│ │ Staging │ │ │ │ Alerts │
│ │ │ Perf │ │ │ │ │ │ │
└─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
JAR Pass Smoke Blue/G Dashboard
Docker >80% Tests Green Grafana
Image Coverage Canary
Stage Details
1. Build Stage
- Checkout code
- Compile source
- Package application
- Create artifacts (JAR, Docker image)
- Push to artifact repository
2. Test Stage
- Unit Tests:
* Fast, isolated tests
* >80% code coverage target
* Run in minutes
- Integration Tests:
* Database interactions
* API endpoints
* Service communication
- Security Scan:
* Dependency vulnerabilities
* Static code analysis (SAST)
* Secrets detection
- Performance Tests:
* Load testing
* Stress testing
* Benchmarks
3. Stage Deploy
- Deploy to staging environment
- Run smoke tests
- Execute acceptance tests
- Validate configuration
- Database migrations (dry-run)
4. Production Deploy
- Blue/Green deployment
- Canary release (5% → 25% → 100%)
- Automated rollback on failure
- Smoke tests in production
- Notify stakeholders
5. Monitor
- Application metrics
- Error rates
- Response times
- Infrastructure health
- Alert on anomalies
Deployment Strategies
Big Bang (All at Once)
Before: After:
v1.0.0 ──> v1.1.0
100% 100%
Pros: Simple, fast Cons: High risk, hard to rollback
Rolling Deployment
Step 1: Step 2: Step 3:
v1 (80%) v1 (50%) v1 (0%)
v2 (20%) ──> v2 (50%) ──> v2 (100%)
Pros: Gradual, resource efficient Cons: Mixed versions running, rollback complex
Blue/Green Deployment
Before: After:
┌──────┐ Live Traffic ┌──────┐ Live Traffic
│ Blue │<────────────────│ Green│
│ v1.0 │ │ v2.0 │
└──────┘ └──────┘
Idle Serving
Instant rollback: Switch traffic back to Blue
Pros: Instant rollback, zero downtime Cons: Double infrastructure required
Canary Deployment
Step 1: Step 2: Step 3:
v1 (95%) v1 (75%) v1 (0%)
v2 (5%) ──> v2 (25%) ──> v2 (100%)
Monitoring:
- Error rate < 1%
- Latency < 200ms
- 5-minute bake time
Pros: Risk mitigation, real user validation Cons: Complex routing, longer deployment time
Feature Flags
if (featureFlags.isEnabled('new-payment-flow')) {
// New code path
processNewPayment();
} else {
// Old code path
processOldPayment();
}
// Rollout: 0% → 5% → 25% → 50% → 100%
// Kill switch: Instantly disable if issues
Pipeline as Code
Benefits
- Version Controlled: Track changes to pipeline
- Reproducible: Same pipeline every time
- Reviewable: Peer review pipeline changes
- Portable: Move between CI/CD tools
- Testable: Validate pipeline changes
Example (Declarative)
# Jenkinsfile (Declarative)
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'mvn clean compile'
}
}
stage('Test') {
parallel {
stage('Unit Tests') {
steps {
sh 'mvn test'
}
}
stage('Integration Tests') {
steps {
sh 'mvn integration-test'
}
}
}
}
stage('Deploy') {
when {
branch 'main'
}
steps {
sh 'deploy.sh'
}
}
}
post {
always {
junit '**/target/surefire-reports/*.xml'
}
failure {
slackSend(color: 'danger', message: 'Build failed!')
}
}
}
Key Metrics
DORA Metrics
-
Deployment Frequency: How often you deploy
- Elite: Multiple times per day
- High: Once per day to once per week
- Medium: Once per week to once per month
- Low: Once per month to once every 6 months
-
Lead Time for Changes: Time from commit to production
- Elite: Less than one hour
- High: One day to one week
- Medium: One week to one month
- Low: One month to 6 months
-
Mean Time to Recovery (MTTR): Time to restore service
- Elite: Less than one hour
- High: Less than one day
- Medium: One day to one week
-
Change Failure Rate: Percentage of deployments causing failures
- Elite: 0-15%
- High: 16-30%
- Medium/Low: 31-45%
Quiz
Quiz
Question 1 of 5What is the main difference between Continuous Delivery and Continuous Deployment?
Next Steps
Now let's explore Jenkins, the most widely used CI/CD automation server.