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 build

Continuous 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 production

Continuous 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          Production

Multi-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: ./publish

Node.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

  1. Faster Release Cycles: Deploy multiple times per day
  2. Early Bug Detection: Catch issues in development
  3. Reduced Risk: Small, incremental changes
  4. Better Quality: Automated testing
  5. Increased Productivity: Less manual work

Key Components

1. Version Control

git add .
git commit -m "Add new feature"
git push origin main

2. 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:latest

Best Practices

  1. Commit frequently: Small, incremental changes
  2. Automate everything: Build, test, deploy
  3. Test in production-like environment: Staging
  4. Monitor deployments: Track metrics
  5. Rollback capability: Quick recovery
  6. 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.

Test Your Cicd Knowledge

Ready to put your skills to the test? Take our interactive Cicd quiz and get instant feedback on your answers.