For customers needing cleanup work to run no matter how a job ends, we now support teardown steps. Add a teardown list to any run step, and CircleCI runs those steps at the end of the job, including when the job fails, is canceled, or times out.
Use teardown for saving caches, storing test results, and other cleanup that would otherwise be skipped when a job ends early. It also lets you place a save_cache near its matching restore_cache, rather than at the end of the job.
steps:
- checkout
- restore_cache:
keys:
- v1-build-{{ checksum "go.sum" }}
- run:
name: Build
command: make build
teardown:
- save_cache:
key: v1-build-{{ checksum "go.sum" }}
paths:
- ~/.cache/go-build
Supported steps: run, save_cache, persist_to_workspace, store_artifacts, and store_test_results. Teardown steps share a 10-minute total time limit per job.
See the teardown configuration reference for details.