# Pipelines as a Product

Course: [CI/CD](https://www.devtutorials.ai/learn/cicd) · Section: Running Pipelines Well
Source: https://www.devtutorials.ai/learn/cicd/running-pipelines-well/pipelines-as-a-product

> Treat the pipeline as a product: call one shared template with inputs, give pipeline files owners with CODEOWNERS, and keep pinned versions fresh with Dependabot.

## Pipelines as a Product

One repo, one pipeline: easy.

Twenty repos, twenty copied pipelines: a mess.

- A fix in one copy never reaches the others.
- Each team pins a different version.
- Anyone can weaken their own copy, and nobody notices.

In this lesson you treat the pipeline like a product the team owns:

- one **shared template** that every repo calls.
- **owners** who review every pipeline change.
- a **bot** that keeps versions fresh.

**Simple lesson:** write the pipeline once, own it, and keep it up to date.

### A Real-World Example

Think about the school's question paper format.

- The exam cell makes **one template**: header, sections, marks.
- Every teacher fills in their own questions.
- Only the exam cell can **change the template**.
- When the board changes a rule, the exam cell updates the template once.

Now map it:

- **The template** = a shared pipeline template.
- **Each teacher's questions** = each repo's inputs, like the Node version.
- **The exam cell** = the platform team, as CODEOWNERS.
- **Board rule updates** = Dependabot pull requests.

**Simple lesson:** one owner, one template, many users.

## Shared Templates

**Template** = a pipeline file other pipelines can call, with inputs.

| Platform | The template | Calling it |
|---|---|---|
| GitHub Actions | A workflow with `on: workflow_call` (a reusable workflow) | A job with `uses: ./.github/workflows/build-template.yml` |
| Azure Pipelines | A YAML file with `parameters:` | A step with `- template: templates/build.yml` |

Here is the team template used in this lesson:

- **Inputs** (GitHub) or **parameters** (Azure) let each repo change a few things.
- Everything else stays the same in every repo.

**Real tools vs this lab:** templates usually live in a separate, shared repo. GitHub calls them as `org/repo/.github/workflows/file.yml@ref`. Azure uses `resources: repositories` and `template: file.yml@name`. In this lab, the template sits in the same repo to keep it simple.

**Simple lesson:** call the template. Do not copy its steps.

### Inputs Change the Behaviour

Pin a shared template from another repo to a tag or commit, just like actions. If you point at `main`, a bad change to the template breaks every repo at once.

**Simple lesson:** a few inputs per repo, one set of steps for all.

## Owners for Pipeline Files

**CODEOWNERS** = a file that says who must review changes to which files.

- Each line: a file pattern, then the owners.
- The **last** matching line wins.
- With branch protection, an owner's review becomes required.

- Now an AI agent or a rushed teammate cannot quietly weaken the pipeline.
- Azure Repos has the same idea: required reviewers for a path, in branch policies.

**Simple lesson:** the people who own the pipeline review every change to it.

## Keep Versions Fresh

You pinned actions to SHAs in Pipeline Security. Pins get old.

**Dependabot** = a GitHub bot that opens pull requests to update versions.

- One entry per kind of package: `github-actions`, `npm`, `nuget`.
- Each update is a normal pull request, so your gates test it.

- Azure DevOps has no built-in Dependabot. Teams often use Renovate, which works with both platforms.

Group small updates into one weekly pull request. Ten tiny pull requests a day get ignored. One tidy one a week gets reviewed.

**Simple lesson:** let a bot propose updates. Let your gates and reviewers decide.

1. Add `.github/CODEOWNERS` to your starter repo with `/.github/ @<your-username>`.
2. Add `.github/dependabot.yml` for `github-actions`, weekly.
3. Push and wait a few days.

**What you should see:** Dependabot pull requests that update your pinned actions, with you asked to review.

## Quick Check

## Cheat Sheet

GitHub reusable workflow call:

```yaml
jobs:
  build:
    uses: ./.github/workflows/build-template.yml
    with:
      node-version: '22'
      run-lint: true
```

Azure template call:

```yaml
steps:
  - template: templates/build.yml
    parameters:
      version: '10'
      runLint: true
```

`.github/CODEOWNERS`:

```text
* @shop/devs
/.github/workflows/ @shop/platform
azure-pipelines.yml @shop/platform
```

`.github/dependabot.yml`:

```yaml
version: 2
updates:
  - package-ecosystem: github-actions
    directory: "/"
    schedule:
      interval: weekly
  - package-ecosystem: npm
    directory: "/"
    schedule:
      interval: weekly
```

## Common mistakes

| Mistake | Wrong idea | Correct idea | What goes wrong |
|---|---|---|---|
| Copying pipelines between repos | Copies are quick | Call one template | Fixes never spread |
| Template from `main` | Always get the latest | Pin a tag or commit | One bad change breaks every repo |
| `*` rule last in CODEOWNERS | Order does not matter | The last match wins | Pipeline files lose their owner |
| No `github-actions` in Dependabot | Pins never need updates | Pins get old | Known bugs stay in your actions |
| Dozens of single update pull requests | More updates = safer | Group them | People stop reviewing them |

## What to Remember

- One shared template, called with a few inputs.
- Pin templates like actions.
- CODEOWNERS: pipeline files belong to the platform team. Last match wins.
- Dependabot or Renovate keeps pins fresh, through normal pull requests.

## Exercises

Next: **Your Pipeline Pack**
