Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for GitLab CI/CD Difficulty: Intermediate ClaudeChatGPT

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

More GitLab CI/CD prompts & error guides

Browse every GitLab CI/CD prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.