Call stage from lifecycle phase?

I have a build with stages for which I’m sharing a docker container by uploading it to a tmp/ repository in ECR. The build’s “happy path” includes a clean stage that removes those temporary images from that repository. The problem, as you might expect, is that, if the build fails in some other stage, the clean stage never gets reached.

Is it possible to tell one of the other stages to call the clean stage from its own after_failure phase?

If there’s a better way to do this, I’m down for that too. The general case is that I want to be able to clean up build artifacts that I have to push in order to share them across build phases.

Thank you!

Actually, there’s a follow-on that might help me clarify: the job each stage doesn’t seem to have its own (complete?) lifecycle. If I add a before_install step, it seems to get executed by every stage. Does that sound like what’s expected?