How to Shut Down Idle CI Resources
A hung job that runs to the six-hour ceiling wastes more energy than any test it was meant to run.
Idle CI resources leak cost quietly: a stuck job burning its full timeout, a preview environment nobody closed, a database left running. Bounding runtime and tearing down environments on close removes that drain.
Steps
- Set
timeout-minuteson every job so a hang is killed, not run to the 360-minute default. - Tear down preview environments when a pull request closes.
- Let service containers stop with the job rather than leaving external ones running.
Workflow
.github/workflows/ci.yml
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- run: npm ci && npm test
cleanup-preview:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- run: ./scripts/destroy-preview.sh "${{ github.event.number }}"Tradeoffs
- Set the timeout slightly above normal duration so healthy runs are not cut off.
- A timed-out job is marked failed and can fail dependents through
needs.
Related guides
How to Scale Self-Hosted CI Runners to Zero When IdleConfigure ephemeral self-hosted GitHub Actions runners that scale to zero when no jobs are queued, so idle ma…
How to Limit CI Artifact RetentionSet short retention on GitHub Actions artifacts so build outputs do not sit in storage for the default 90 day…