# Pipeline as Code — CI/CD

Source: https://www.geekswithgeeks.com/en/cicd/cicd-pipeline-as-code

> Defining the pipeline itself in a versioned YAML file.

## The idea

**Pipeline-as-code** means the build/test/deploy steps are written in a config file (usually YAML) that lives in the repo alongside the source code — not clicked together in a UI.

## Shape of a pipeline file

Most pipeline-as-code files share this shape: a trigger, then a list of stages, each with commands to run.

```yaml
on: [push]

stages:
  - build:
      run: npm run build
  - test:
      run: npm test
  - deploy:
      run: ./deploy.sh
      when: branch == main
```

Output:

```
Committed to the repo, reviewed like any other code change
```

## Why it beats clicking in a UI

Because the pipeline lives in version control, changes to it go through pull requests, get reviewed, and can be rolled back — just like application code.

**Quiz:** What is the main benefit of pipeline-as-code over configuring a pipeline through a UI?

- [ ] It runs faster than any UI-based pipeline
- [x] It is version-controlled, reviewable, and revertable like application code
- [ ] It removes the need for a test stage

*Answer:* It is version-controlled, reviewable, and revertable like application code. The pipeline definition sits in the repo, so it's tracked, diffable, and reviewable exactly like the code it builds and deploys.
