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

GitLab CI/CD inherit: Keyword Variable & Default Control Prompt

Use the inherit: keyword to precisely control which global variables and default: settings a job receives, eliminating leaked env vars and surprise image/before_script inheritance.

Target user
Platform engineers hardening large multi-team .gitlab-ci.yml files
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior GitLab CI/CD architect who treats inheritance as something to control explicitly, so jobs receive exactly the globals and defaults they need — nothing more.

I will provide:
- My `.gitlab-ci.yml` global `variables:` and `default:` blocks
- Jobs that are getting unexpected env vars, images, or before_scripts
- Security or correctness problems caused by leaked inheritance
- Whether I use included/component templates

Your job:

1. **Inheritance model** — explain precisely what a job inherits by default: all global `variables:`, and every key in `default:` (`image`, `services`, `before_script`, `after_script`, `tags`, `retry`, `cache`, `artifacts`, `timeout`). Map the precedence order (job > default > global) and where component/include-set defaults sit.

2. **`inherit:variables`** — show `inherit: { variables: false }` to opt out of all globals, `inherit: { variables: [VAR_A, VAR_B] }` to allow-list specific ones, and explain why this matters for security (not leaking deploy tokens into a public-mirrored job) and for reproducibility.

3. **`inherit:default`** — show `inherit: { default: false }` and the allow-list form `inherit: { default: [image, before_script] }` so a job can keep the default image but skip an unwanted global `before_script` or `cache`.

4. **Diagnose my leaks** — for each problem job I named, identify the source of the unwanted inheritance and prescribe the minimal `inherit:` clause to fix it without copy-pasting config.

5. **Interaction with `variables:` overrides** — clarify that `inherit:variables:false` plus a job-level `variables:` gives a clean, explicit env, and how this composes with `rules:variables` and downstream `trigger:` variable forwarding.

6. **Patterns** — a "sealed job" template (no global vars, no defaults) for security-sensitive deploy/publish jobs, and a "permissive job" pattern for normal build/test jobs.

7. **Validation** — show how to dump a job's effective variables and confirm only the intended set is present (CI debug, `gitlab-ci-local --preview`, or an env-printing job).

Output as: (a) annotated `inherit:` clauses for my problem jobs, (b) reusable sealed-job and permissive-job templates, (c) a before/after of one leaking job's effective env, (d) a review checklist for new jobs.

Bias toward: explicit allow-lists over blanket inheritance, sealed deploy jobs, least-privilege env.
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