DEV Community

Cover image for A Complete Guide to CI/CD Pipelines — From Zero to Deployment
Farhad Rahimi Klie
Farhad Rahimi Klie

Posted on • Edited on

A Complete Guide to CI/CD Pipelines — From Zero to Deployment

1. What is CI/CD?

CI/CD stands for:

  • CI → Continuous Integration
  • CD → Continuous Delivery / Continuous Deployment

CI/CD is an automated pipeline that takes your code from:

Commit → Build → Test → Package → Deploy

Without manual intervention.


2. Why CI/CD Exists

Before CI/CD:

  • Manual builds
  • Manual testing
  • Manual deployments
  • Human errors
  • “It works on my machine” problem

CI/CD solves:

  • Integration conflicts
  • Broken releases
  • Slow delivery
  • Inconsistent environments

3. CI vs CD (Clear Difference)

Continuous Integration (CI)

CI focuses on code quality.

Goals:

  • Validate code on every commit
  • Catch bugs early
  • Run automated tests

CI includes:

  • Linting
  • Unit tests
  • Build verification

Continuous Delivery (CD)

CD focuses on release readiness.

Goals:

  • Code is always deployable
  • Deployment is automated but manual trigger

Continuous Deployment

  • Every successful pipeline auto-deploys to production
  • No human approval

4. CI/CD Pipeline Architecture

High-Level Architecture

Developer
   ↓
Source Control (Git)
   ↓
CI Server
   ↓
Build System
   ↓
Test System
   ↓
Artifact Repository
   ↓
Deployment System
   ↓
Production
Enter fullscreen mode Exit fullscreen mode

Logical Architecture Layers

  1. Source Layer – Git repository
  2. Trigger Layer – Webhooks
  3. Execution Layer – Runners / Agents
  4. Validation Layer – Tests & analysis
  5. Packaging Layer – Artifacts
  6. Deployment Layer – Servers / Cloud
  7. Feedback Layer – Logs & alerts

5. Internal Components of a CI/CD System

1. Source Control System (SCM)

Examples:

  • GitHub
  • GitLab
  • Bitbucket

Responsibilities:

  • Version control
  • Branching
  • Pull requests

2. CI/CD Orchestrator

Examples:

  • GitHub Actions
  • GitLab CI
  • Jenkins

Responsibilities:

  • Pipeline execution
  • Job scheduling
  • Dependency resolution

3. Runner / Agent

  • Executes pipeline jobs
  • Can be:

    • Docker container
    • VM
    • Bare metal

4. Artifact Storage

Stores:

  • Build outputs
  • Docker images
  • Binaries

Examples:

  • Nexus
  • Artifactory
  • GitHub Packages

5. Deployment Target

  • VPS
  • Kubernetes
  • Cloud services
  • Serverless platforms

6. CI/CD Workflow (Step by Step)

  1. Developer pushes code
  2. Webhook triggers pipeline
  3. Runner spins up environment
  4. Dependencies installed
  5. Code is built
  6. Tests run
  7. Artifact created
  8. Artifact deployed
  9. Monitoring validates deployment

7. Pipeline Stages Explained in Depth

Stage 1: Checkout

git clone https://github.com/user/repo.git
Enter fullscreen mode Exit fullscreen mode

Stage 2: Install Dependencies

npm install
Enter fullscreen mode Exit fullscreen mode

or

pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Stage 3: Linting

npm run lint
Enter fullscreen mode Exit fullscreen mode

Purpose:

  • Enforce coding standards
  • Catch syntax issues

Stage 4: Testing

npm test
Enter fullscreen mode Exit fullscreen mode

Types:

  • Unit tests
  • Integration tests
  • End-to-end tests

Stage 5: Build

npm run build
Enter fullscreen mode Exit fullscreen mode

Output:

  • Compiled code
  • Bundled assets

Stage 6: Artifact Packaging

docker build -t myapp:1.0 .
Enter fullscreen mode Exit fullscreen mode

Stage 7: Deployment

docker run -d -p 80:3000 myapp:1.0
Enter fullscreen mode Exit fullscreen mode

8. CI/CD Configuration Syntax (YAML Explained)

CI/CD pipelines are written in YAML.

Core YAML Concepts

  • stages
  • jobs
  • steps
  • scripts
  • artifacts
  • variables

9. Popular CI/CD Tools Overview

Tool Type Strength
GitHub Actions Cloud GitHub native
GitLab CI Cloud / Self All-in-one
Jenkins Self-hosted Highly customizable
CircleCI Cloud Speed
Azure DevOps Cloud Enterprise

10. Complete CI/CD Examples (Real Code)

GitHub Actions — Node.js App

name: CI-CD Pipeline

on:
  push:
    branches: [ "main" ]

jobs:
  build-test-deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 18

      - name: Install dependencies
        run: npm install

      - name: Run tests
        run: npm test

      - name: Build app
        run: npm run build

      - name: Deploy
        run: echo "Deploying application..."
Enter fullscreen mode Exit fullscreen mode

GitLab CI Example

stages:
  - build
  - test
  - deploy

build_job:
  stage: build
  script:
    - npm install
    - npm run build

test_job:
  stage: test
  script:
    - npm test

deploy_job:
  stage: deploy
  script:
    - echo "Deploying..."
Enter fullscreen mode Exit fullscreen mode

11. Environment Management

Typical environments:

  • development
  • staging
  • production

Use environment variables:

env:
  NODE_ENV: production
Enter fullscreen mode Exit fullscreen mode

12. Secrets & Credentials Handling

Never hardcode secrets.

Use:

  • GitHub Secrets
  • GitLab Variables
  • Vaults
env:
  DATABASE_URL: ${{ secrets.DB_URL }}
Enter fullscreen mode Exit fullscreen mode

13. Artifact Management

Artifacts include:

  • .zip
  • .jar
  • Docker images
artifacts:
  paths:
    - dist/
Enter fullscreen mode Exit fullscreen mode

14. Deployment Strategies

Blue-Green Deployment

  • Two environments
  • Switch traffic instantly

Canary Deployment

  • Deploy to small subset first

Rolling Deployment

  • Gradual replacement

15. Rollbacks & Failure Handling

  • Automatic rollback
  • Versioned artifacts
  • Health checks
docker rollback myapp
Enter fullscreen mode Exit fullscreen mode

16. Monitoring & Observability

After deployment:

  • Logs
  • Metrics
  • Alerts

Tools:

  • Prometheus
  • Grafana
  • ELK Stack

17. Security in CI/CD (DevSecOps)

Security checks:

  • SAST
  • DAST
  • Dependency scanning
npm audit
Enter fullscreen mode Exit fullscreen mode

18. Advanced CI/CD Concepts

  • Pipeline caching
  • Parallel jobs
  • Matrix builds
  • Infrastructure as Code (IaC)
  • GitOps

19. Common Mistakes & Anti-Patterns

❌ No tests
❌ Hardcoded secrets
❌ Manual deployments
❌ No rollback strategy
❌ Single environment


20. CI/CD Best Practices

✔ Keep pipelines fast
✔ Fail fast
✔ Automate everything
✔ Treat pipeline as code
✔ Secure secrets


21. CI/CD Mental Model (How to Think Like a Pro)

Think of CI/CD as:

A factory line for software

  • Input → code
  • Output → reliable production release
  • Automation replaces humans
  • Feedback loops improve quality

Final Words

CI/CD is not a tool, not YAML, and not GitHub Actions.

It is:

A mindset + architecture + automation strategy

Mastering CI/CD means:

  • Faster releases
  • Higher quality
  • Zero fear of deployment

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.