I’m wondering if there’s any way to run some code if the timeout is reached, before the command in the bat step is terminated by Jenkins? I’ve searched around, and even asked AI, but I can’t find much information on the topic. Is it maybe possible to catch an exception higher up the chain, or some other less well known method?
Sadly, catching exceptions won’t do good here; even if you were to do it backwards, timeout { try {...} catch {...} }, by the time you land in catch{} the kill signal has already been sent.
Just an idea you could try to split this in 2 different threads with a parallel step
The first does the actual workload. Once it finished it sets a property,
the other thread will just sleep for a few seconds and then checks if the time is over or the other thread has finished and set the property. If the time is over it can do whatever it needs to cleanup things while the other is still running and then fails. If the cleanup makes the other thread fail then good otherwise you will need failFast for the parallel step probably.
It’s a bit hacky and when you use the sleep step in that waiting thread it will spam your logs.