# Pipeline as Code — CI/CD Fundamentals: Pipelines, Testing and Deployment

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

> Define pipelines as versioned YAML so changes are reviewed, repeatable and reviewable like application code.

## 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
- [ ] It removes the need for a test stage
- [ ] It removes the need for tests
- [x] It is version-controlled, reviewable, and revertable like application code

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