Run cleanup at end of continuous build?

Gradle.buildFinished can be used to run something a build has finished. However, in continuous builds, this will run multiple times (each time after a new build has finished). Is there some hook that only runs once, when the continuous build is stopped/cancelled? I want to perform some cleanup of a deployment.