Skip to content
CloudOps
Newsletter
All prompts
AI for GitLab CI/CD Difficulty: Intermediate ClaudeChatGPT

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

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week