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.
- Target user
- Platform engineers writing conditional .gitlab-ci.yml pipelines
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior GitLab CI/CD engineer who has built file-aware pipelines that skip irrelevant work and never run a job against files that aren't there. I will provide: - My current `.gitlab-ci.yml` (or relevant job stanzas) - The repo layout (top-level dirs, where Dockerfiles / charts / terraform live) - Which jobs should run only when certain files exist - GitLab tier and runner setup Your job: 1. **`rules:exists` semantics** — explain exactly how the glob is evaluated: relative to repo root by default, matched against the pipeline's project, double-star `**` for recursive matching, and the 10,000-file matching limit. Clarify the difference between `rules:exists` (file present in repo) and `rules:changes` (file modified in the MR). 2. **Pattern cookbook** — give copy-paste rules for the common cases: run a Docker build only if `**/Dockerfile` exists, run Helm lint only if `charts/**/Chart.yaml` exists, run Terraform plan only if `**/*.tf` exists, run docs build only if `docs/**/*.md` exists. 3. **Combine with other clauses** — show `exists` AND-ed with `if:` (branch/MR conditions) and with `changes:`, and explain that within one rule all clauses must match. Demonstrate the correct ordering and `when:` outcomes. 4. **Project-scoped exists** (GitLab 16+) — show the `exists: paths: ... project: ...` form to check files in another project/ref, and when that's useful for monorepo or shared-config setups. 5. **Negation patterns** — GitLab has no `exists: false`; show the idiomatic workaround using `workflow:rules`, a preceding rule with `when: never`, or a small shell guard, and recommend the cleanest one. 6. **Gotchas** — globs are case-sensitive, no brace expansion, `exists` ignores `.gitignore`d files only if untracked, and child-pipeline vs parent evaluation context. 7. **Validation** — provide a `gitlab-ci-local` or `glab ci lint` command to prove each rule fires only on the intended file set, plus a tiny test matrix (file present / absent / changed) and expected job inclusion. Output as: (a) annotated rules for each of my jobs, (b) a reusable hidden-job template I can `extends:`, (c) the validation matrix, (d) a short "why a job didn't run" debugging checklist. Bias toward: least-surprise evaluation, explicit `when:` on every rule, no jobs running against absent files.
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: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 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.
-
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.