So in ruby there is an at_exit hook. but this isn't cucumber, it's programmatically related. I would look inside your language to see if this is possible.
Failing that, you can store a class variable during your run of the number of failures. then if all of those have passed then you can do something.
Another way you could tackle it would be to wrap your execution job in something like jenkins, jenkins has nice simple out of the box methods for cleaning things up.
In Jenkinsfile's both declarative and scripted pipelines allow the calling of cleanWs()
as a groovy statement which then wipes the entire jenkins node.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…