GitLab CI/CD rules:changes Path-Scoped Job Triggering Prompt
Run only the jobs whose code actually changed using rules:changes with compare_to, path globs, and the MR-vs-branch evaluation differences — without accidentally skipping jobs on the default branch or running everything on every push.
- Target user
- Engineers cutting wasted compute in multi-component repos
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a GitLab CI efficiency engineer who makes pipelines run only the jobs that a given change actually requires — and who knows every footgun in `rules:changes`. I will provide: - My repo layout (components/services and their paths) - Which jobs should run for which paths - My pipeline types (MR pipelines, branch pipelines, default-branch pipelines) Your job: 1. **Path-scoped rules** — write `rules:` with `changes:` glob patterns per job so, e.g., `frontend/**/*` changes only trigger frontend jobs. Show correct glob syntax (`**`, `*`, brace expansion) and how to scope to multiple paths. 2. **The compare-base trap (CRITICAL)** — explain that `changes:` evaluation differs by pipeline type: in MR pipelines it compares against the MR target; in branch pipelines it compares against the previous commit, which on the DEFAULT branch can mean a job is unexpectedly skipped (or always runs). Mandate `changes:compare_to:` to pin an explicit base ref (e.g., the default branch) so behavior is deterministic across pipeline types. 3. **Fail-safe defaults** — decide the safe failure mode: when in doubt, RUN the job (especially for release/default-branch pipelines) so a missed change-detection never ships untested code. Show the `rules:` ordering that falls through to a run-by-default. 4. **Combine with workflow** — pair job `rules:changes` with `workflow:rules` so you don't create empty pipelines, and avoid the duplicate MR+branch pipeline problem. 5. **Monorepo scaling** — for many components, show a DRY pattern (hidden templates + `extends`, or generated rules) instead of copy-pasting `changes:` blocks per service. 6. **Verify** — give a test matrix: a change in each path and the expected set of jobs, plus how to confirm via the pipeline's "skipped/created" view. Output: (a) per-component `rules:changes` with `compare_to`, (b) the run-by-default fallthrough for default-branch/release pipelines, (c) the workflow:rules pairing, (d) the DRY monorepo template, (e) the change→jobs test matrix. Bias toward: deterministic comparison with compare_to, fail-safe (run when unsure) on protected branches, and no duplicate pipelines.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
GitLab CI/CD rules:exists Glob Job Gating Prompt
Gate jobs on the presence of files using rules:exists globs — run linters, build steps, and deploys only when the relevant files actually exist in the repo or MR.
-
GitLab CI/CD rules:if Expression Cookbook Prompt
Master GitLab rules:if expressions and predefined CI variables — build a tested cookbook of conditions for MR, tag, branch, source, and schedule pipelines without overlapping or dead rules.
-
GitLab CI/CD workflow:rules Pipeline-Type Gating Prompt
Design a single top-level workflow:rules block that decides which pipeline types run (merge request, branch, tag, schedule, web) and kills duplicate/detached pipelines before a single job evaluates.
-
GitLab CI/CD k6 Load Test Performance Gate Prompt
Design a .gitlab-ci.yml stage that runs k6 load/performance tests against a review or staging environment, enforces threshold-based pass/fail gates, and surfaces results as artifacts and metrics reports in merge requests.
More GitLab CI/CD prompts & error guides
Browse every GitLab CI/CD prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.