What is CI/CD?
Definition
CI/CD stands for Continuous Integration and Continuous Deployment/Delivery. It’s a method to frequently deliver apps to customers by introducing automation into the stages of app development.
Continuous Integration (CI)
Developers merge code changes into a central repository frequently, after which automated builds and tests run.
# Example: GitHub Actions CI
name: CI Pipeline
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build
run: npm run buildContinuous Delivery (CD)
Code changes are automatically built, tested, and prepared for release to production.
# Continuous Delivery
deploy-staging:
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to Staging
run: |
echo "Deploying to staging..."
# Manual approval required for productionContinuous Deployment
Every change that passes tests is automatically deployed to production.
# Continuous Deployment
deploy-production:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy to Production
run: |
echo "Deploying to production..."
kubectl apply -f k8s/CI/CD Pipeline Flow
Developer → Commit Code → Version Control (Git)
↓
CI Server (Build & Test)
↓
┌─────────┴─────────┐
↓ ↓
Continuous Delivery Continuous Deployment
↓ ↓
Manual Approval Auto Deploy
↓ ↓
Production ProductionMulti-Stack Examples
Angular Application
# .github/workflows/angular-ci.yml
name: Angular CI/CD
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Test
run: npm run test:ci
- name: Build
run: npm run build --prod
- name: Deploy to Firebase
run: |
npm install -g firebase-tools
firebase deploy --token ${{ secrets.FIREBASE_TOKEN }}.NET Application
# .github/workflows/dotnet-ci.yml
name: .NET CI/CD
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
- name: Publish
run: dotnet publish -c Release -o ./publish
- name: Deploy to Azure
uses: azure/webapps-deploy@v2
with:
app-name: my-dotnet-app
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }}
package: ./publishNode.js Application
# .github/workflows/nodejs-ci.yml
name: Node.js CI/CD
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Run tests
run: npm test
- name: Build Docker image
run: docker build -t myapp:${{ github.sha }} .
- name: Push to registry
run: |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
docker push myapp:${{ github.sha }}Benefits
- Faster Release Cycles: Deploy multiple times per day
- Early Bug Detection: Catch issues in development
- Reduced Risk: Small, incremental changes
- Better Quality: Automated testing
- Increased Productivity: Less manual work
Key Components
1. Version Control
git add .
git commit -m "Add new feature"
git push origin main2. Automated Testing
// Jest test example
describe('UserService', () => {
it('should create user', async () => {
const user = await userService.create({
email: 'test@example.com'
});
expect(user.id).toBeDefined();
});
});3. Build Automation
# Package.json scripts
{
"scripts": {
"build": "npm run build:prod",
"test": "jest",
"lint": "eslint src/",
"deploy": "npm run build && npm run deploy:prod"
}
}4. Deployment Automation
# Deploy script
#!/bin/bash
npm run build
docker build -t myapp:latest .
docker push myapp:latest
kubectl set image deployment/myapp myapp=myapp:latestBest Practices
- Commit frequently: Small, incremental changes
- Automate everything: Build, test, deploy
- Test in production-like environment: Staging
- Monitor deployments: Track metrics
- Rollback capability: Quick recovery
- Security scanning: Automated checks
Interview Tips
- Explain CI/CD: Automation of build, test, deploy
- Show pipeline: Complete workflow example
- Demonstrate multi-stack: Angular, .NET, Node.js
- Discuss benefits: Speed, quality, reliability
- Mention tools: GitHub Actions, Jenkins, GitLab CI
- Show best practices: Testing, monitoring, rollback
Summary
CI/CD automates the software delivery process from code commit to production deployment. Continuous Integration merges code frequently with automated testing. Continuous Delivery prepares code for release. Continuous Deployment automatically releases to production. Works across all tech stacks including Angular, .NET, Node.js, and databases. Essential for modern software development.
Test Your Knowledge
Take a quick quiz to test your understanding of this topic.