Add suspend/resume support to GitLab Runner (Suspendable Environments)
Summary
Adds suspend/resume capability to GitLab Runner, allowing job environments to be preserved across sessions instead of being destroyed. Jobs opt in via CI_SUSPEND_ON_SUCCESS or CI_SUSPEND_ON_FAILURE. On the next run, the resume key is passed as CI_SUSPENDABLE_ENVIRONMENT_RESUME_KEY and the runner resumes the exact same instance with disk state intact.
All changes are behind the FF_SUSPENDABLE_ENVIRONMENTS feature flag (default: off).
Changes
- FF_SUSPENDABLE_ENVIRONMENTS feature flag
- SuspendableExecutor interface for runtime discovery of suspension support
- trace.Suspend(resumeKey) on the JobTrace interface (logs the key; Rails integration pending)
- Resume key compose/parse utilities with forward-compatible format (/="",...)
- Autoscaler provider: suspend path in Release() (calls scaler.Suspend, composes resume key, emits via trace)
- Autoscaler executor: resume path in Prepare() (parses resume key, calls scaler.Resume, restores connection)
- Validation: capability check on both suspend and resume paths, nil guard for uninitialized scaler
- Git source fetching skipped on resume — the working directory is preserved from the suspended job
- When FF_SUSPENDABLE_ENVIRONMENTS is off, CI variables are silently ignored (no job failure)
CI Variables
| Variable | Purpose |
|---|---|
| CI_SUSPEND_ON_SUCCESS=true | Suspend after successful job completion |
| CI_SUSPEND_ON_FAILURE=true | Suspend after job failure (CI debugging) |
| CI_SUSPENDABLE_ENVIRONMENT_RESUME_KEY | Resume key from a prior suspension (input) |
Testing
Covers shouldSuspend and getResumeKey helpers (all FF/variable/outcome combinations), validateSuspension (nil scaler, missing capability, FF gating), resume key edge cases (deterministic ordering, empty values, special characters, malformed input), and SuspendableExecutor interface compliance.
Related
Edited by Vishal Tak