| Aha – in my case the answer was that an error was being thrown by the build before it got into the pipeline stages, specifically by a credentials('SOME_ID') command being used in a root-level environment block, for a credential ID that didn't exist. This failed the build immediately, but because cleanWS() was in an always block, it tried to execute it, and the agent node hadn't actually been (fully?) allocated yet, hence this error. The error obscured the true root cause, and arguably cleanWs() could have been more tolerant of these conditions rather than throwing, but at least I have an explanation now. |