DevOps Bootcamp · Lesson

Path Filtering and Selective Builds

Trigger only the workflows and jobs affected by a change using path filters, change detection, and conditional matrices in monorepos and multi-repo setups.

Lesson 4 of 413 steps

Path Filtering and Selective Builds is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 4 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.

The Wasted Build Problem

In a monorepo, a change to the documentation should not rebuild and redeploy the backend, the frontend, and the mobile app.

Selective builds run only the parts of the pipeline affected by a change, saving time and runner minutes.

Path Filters on Triggers

The simplest approach is the paths filter on the trigger. A workflow only runs when files matching the pattern change.

on:
  push:
    paths:
      - 'services/api/**'

Ignoring Paths

You can also do the inverse with paths-ignore: run the workflow for everything except the listed paths.

This is handy to skip CI for documentation-only changes.

on:
  push:
    paths-ignore:
      - 'docs/**'
      - '**.md'

Limits of Trigger Filters

Trigger-level filters decide whether the whole workflow runs. But in a monorepo you often want one workflow that decides which jobs to run.

For that, you detect changes inside the workflow and branch on the result.

Change Detection Action

The dorny/paths-filter action inspects the diff and outputs booleans for each named group of paths.

Later jobs read those outputs to decide whether to run.

  - uses: dorny/paths-filter@v3
    id: changes
    with:
      filters: |
        api:
          - 'services/api/**'
        web:
          - 'services/web/**'

Gating Jobs on Detected Changes

A detection job exposes outputs; downstream jobs use if with the needs context to run conditionally.

  build-api:
    needs: detect
    if: needs.detect.outputs.api == 'true'
    runs-on: ubuntu-latest
    steps:
      - run: ./build-api.sh

Wiring Up the Outputs

The detection job must declare outputs that forward the filter results so other jobs can read them.

  detect:
    runs-on: ubuntu-latest
    outputs:
      api: ${{ steps.changes.outputs.api }}
      web: ${{ steps.changes.outputs.web }}

Dynamic Matrices

For many services you can build a matrix dynamically from the changed paths, so only changed services enter the matrix.

Generate a JSON list in one job and feed it into the matrix of the next.

    strategy:
      matrix:
        service: ${{ fromJSON(needs.detect.outputs.list) }}

Git Diff for Detection

You can also detect changes with raw git. Compare the current commit against the base to list changed directories.

git diff --name-only origin/main...HEAD | cut -d/ -f1-2 | sort -u

Required Checks and Skips

Beware: if a required status check is skipped because nothing changed, branch protection may block the merge waiting for it.

The fix is to add a final gate job that always succeeds and is the only required check, summarizing the conditional jobs.

  gate:
    needs: [build-api, build-web]
    if: always()
    runs-on: ubuntu-latest
    steps:
      - run: echo 'all required jobs resolved'

Caching Per Package

Selective builds pair well with per-package caches. Key the cache on each service's lockfile so unrelated changes do not invalidate it.

Together they keep monorepo pipelines fast even as the repo grows.

Quick Check

Test your understanding of selective builds.

Recap

You learned to build only what changed.

  • paths and paths-ignore gate whole workflows
  • Change-detection actions output per-path booleans
  • Jobs use if + needs to run conditionally, and matrices can be built dynamically
  • Add an always() gate job for required-check compatibility

Selective builds keep monorepo CI/CD fast and economical.

Free to start

Learn DevOps Bootcamp with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
142
Lessons
568

Frequently Asked Questions

Is the “Path Filtering and Selective Builds” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Path Filtering and Selective Builds”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.

What will I learn in “Path Filtering and Selective Builds”?

Trigger only the workflows and jobs affected by a change using path filters, change detection, and conditional matrices in monorepos and multi-repo setups. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.

How long does the “Path Filtering and Selective Builds” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. CI/CD for Monorepos
  2. Cross-Repository Workflows
  3. Centralized Workflow Management
  4. Path Filtering and Selective Builds
← Back to DevOps Bootcamp