GitLab CI Pre/Post Stage & Global Hooks Prompt
Design reliable setup and teardown logic using the .pre and .post stages plus default before_script/after_script hooks without coupling jobs or hiding failures.
- Target user
- Platform engineers structuring GitLab pipeline lifecycle hooks
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior CI/CD engineer who specializes in GitLab pipeline lifecycle structure. I will provide: - The cross-cutting setup/teardown logic I want (auth, cache warm, notifications, cleanup) - The current stage list and any `default:` block with before_script/after_script - Which jobs must opt out of the shared hooks - Whether teardown must run even when earlier jobs fail Your job: 1. **Place lifecycle jobs** — decide what belongs in the `.pre` stage (runs first) vs `.post` stage (runs last regardless of pipeline result) vs a `default:` hook. 2. **Choose hook vs job** — distinguish per-job `before_script`/`after_script` from pipeline-level `.pre`/`.post` jobs, and avoid duplicating logic. 3. **Guarantee teardown** — ensure `.post` cleanup/notification runs even on failure, using `when:` and rules so it is not skipped. 4. **Scope opt-outs** — show how specific jobs override or clear inherited `default:` scripts via `inherit:` controls. 5. **Prevent silent failures** — make sure a failing hook surfaces as a job failure rather than being swallowed by after_script semantics. Output as: (a) a lifecycle placement table, (b) the `.pre`/`.post` job definitions, (c) the `default:` and inherit overrides, (d) a failure-path walkthrough. Default to making teardown jobs run with `when: always` and surface their errors; never hide setup failures inside after_script where they cannot fail the pipeline.
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 Android Signed APK/AAB Build Pipeline Prompt
Build, test, and sign Android APK/AAB artifacts in GitLab CI — keystore secrecy, Gradle caching, SDK licenses, and Play Store upload without leaking signing keys.
-
GitLab CI/CD Container Image Size Budget Gate Prompt
Add an image-size budget gate to GitLab CI — measure built image size, diff against a baseline, and fail the pipeline when a layer bloats the image past budget.
-
GitLab CI/CD Playwright Sharded E2E Test Pipeline Prompt
Run Playwright end-to-end tests sharded across GitLab CI jobs — browser caching, blob-report merge, flaky retries, traces on failure, and a single merged HTML report.
-
GitLab CI/CD FIPS-Compliant Runner Hardening Prompt
Stand up and validate FIPS 140-compliant GitLab Runners and pipelines — FIPS images, crypto policy, verification, and avoiding silent non-compliant fallbacks.
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.