# CI/CD Pipelines

CI/CD stands for **Continuous Integration** and **Continuous Delivery/Deployment**. It is a method to frequently deliver apps to customers by introducing automation into the stages of app development.

## 1. Continuous Integration (CI)

CI is the practice of automating the integration of code changes from multiple contributors into a single software project.

*   **Process:** Developers frequently commit code to a shared repository (like GitHub). Each commit triggers an automated workflow that builds the code and runs tests.
*   **Goal:** To find and fix bugs quicker, improve software quality, and reduce the time it takes to validate and release new software updates.

## 2. Continuous Delivery vs. Deployment

While often used interchangeably, there is a subtle difference:

*   **Continuous Delivery:** The code changes are automatically built, tested, and prepared for a release to production. It requires a **manual approval** step to actually deploy to the live environment.
*   **Continuous Deployment:** Every change that passes all stages of your production pipeline is released to your customers **automatically**. There is no human intervention.

## 3. The Pipeline Stages

A typical pipeline consists of several sequential stages:

1.  **Source:** A developer commits code to the version control system.
2.  **Build:** The application is compiled. Dependencies are installed. Docker images are built.
3.  **Test:** Automated tests (Unit, Integration) are run to ensure the new code didn't break anything.
4.  **Deploy (Staging):** The app is deployed to a staging environment that mimics production for final review.
5.  **Deploy (Production):** The app is deployed to the live servers.

## 4. Common Tools

*   **GitHub Actions:** Integrated directly into GitHub. Uses YAML files.
*   **Jenkins:** The classic open-source automation server. Highly customizable but complex.
*   **GitLab CI:** Built into GitLab.
*   **CircleCI:** A popular cloud-based CI/CD platform.

## 5. Example: GitHub Actions Workflow

Here is a simple example of a workflow defined in `.github/workflows/main.yml` that runs tests whenever code is pushed.

```yaml
name: Node.js CI

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js
      uses: actions/setup-node@v3
      with:
        node-version: '18.x'
    - run: npm ci
    - run: npm run build --if-present
    - run: npm test
```

[[programming/docker-and-containers]]
[[programming/microservices-architecture]]
[[programming/debugging-techniques]]