GitLab CI/CD Automated Rollback on Failed Deploy Prompt
Add automatic rollback to a deployment pipeline — health-check the new release, and on failure revert to the last-known-good version using environment auto-rollback or an explicit on_failure rollback job.
- Target user
- SREs hardening deploy pipelines against bad releases
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are an SRE who builds deployment pipelines that fail safe — a bad release is automatically reverted before it pages anyone. I will provide: - My deploy target (Kubernetes/Helm, plain VM, serverless) and current deploy job - How I'd detect a bad release (HTTP health check, smoke tests, error-rate query) - What "last known good" means for me (previous image tag, previous Helm revision) Your job: 1. **Pin the rollback target** — before deploying, capture the current good state (e.g., `helm history`/current revision, the currently-running image tag, the previous successful deployment SHA) and persist it as a dotenv artifact so the rollback job knows what to revert to. 2. **Post-deploy verification** — add a `verify` job that runs smoke tests / health checks / an error-rate query against the new release with a bounded timeout and retries. Make its failure the trigger for rollback. 3. **Rollback mechanism** — design the rollback job with `when: on_failure` wired via `needs:` to the verify job (so it only runs when verification fails), executing `helm rollback`, re-deploying the captured previous tag, or `kubectl rollout undo`. Make rollback idempotent and safe to re-run. 4. **GitLab environment semantics** — show how to record the deployment so the environment's "last successful deployment" stays correct after a rollback, and discuss GitLab's built-in environment rollback button vs a scripted rollback. Use `resource_group:` so a rollback can't race a concurrent deploy. 5. **Notify & block** — on rollback, post to Slack/MR, fail the pipeline (so it's visibly red), and prevent the bad SHA from auto-promoting further. 6. **Failure-mode review** — what if the rollback itself fails? Define the manual break-glass path and an alert. 7. **Test it** — give me a way to force a failing verify (feature flag / fault injection) to prove rollback actually fires end-to-end. Output: (a) capture-good-state job, (b) deploy job, (c) verify job, (d) `on_failure` rollback job with the chosen mechanism, (e) the forced-failure test plan. Bias toward: automatic revert on verification failure, idempotent rollback, and an explicit break-glass for rollback-of-rollback.
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 Helm Chart Deploy Prompt
Build a GitLab CI/CD pipeline that lints, packages, and deploys Helm charts to Kubernetes with per-environment values, atomic upgrades, diff previews, and safe rollbacks.
-
GitLab CI/CD Job Timeout Budget Tuning Prompt
Set per-job and per-runner timeout budgets so hung jobs fail fast instead of burning the project timeout, and slow jobs are caught before they block merge trains or deploys.
-
GitLab CI/CD when:manual Confirmation Deploy Gate Prompt
Build deliberate manual deploy gates with when:manual, manual_confirmation prompts, allow_failure, and protected environments so production deploys require an explicit, attributable human click.
-
GitLab CI/CD Deploy Freeze Windows Prompt
Configure GitLab deploy freeze periods so production deployments are automatically blocked during change-freeze windows, holidays, or on-call gaps — with clear overrides and visibility.
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.