Gitlab-ci.yml when on_failure on_success

Thinking about CI and trying to get the right mental model. Specifically I am trying to understand the function of the “when” keyword, in light of “stages” behavior.

My understanding is that only items specifically identified with the artifacts keywords are preserved between jobs of a stage and jobs of a successive stage (for example, between build and test stages). Likewise, I remember reading somewhere that jobs within a stage can (and will) be run simultaneously on multiple machines, and thus there is no sequencing of jobs within a stage.

In light of this, I am confused by where it provides an example of the use of the “when” keyword. Any cleanup one might do in “cleanup_build_job” after the “build” stage there would seem to be moot. likewise, is there any guarantee that cleanup_build_job is run on the same (all) runners that build_job is run on and failed? By then the job “build_job” would have completed, and artifacts zipped up (on success only?) and moved back to the gitlab server. The only utility I could see for an on_failure is in freeing up disk space on the (shell) runner so that the build of other projects would not be impacted by disk space use.

Am I correct in this? Or is there a utility in “when: on_failure” and “when on_success” that I am missing? Have I mis-interpreted something about how (shell) runners work?

It doesn’t appear so. I am trying to find a way to clean up the same runner as the failed build, however it doesn’t seem like this is possible, at the moment.