So I'm generalizing this ticket! There are multiple cases where we want to be able to "leave" the node block created at the top-level by use of anything but agent none but then "return" to it after a stage with a different agent (particularly agent none) has completed. There's lock, there's the throttle step I've been working on in JENKINS-31801, there's CloudBees' proprietary checkpoint feature, there's the input step, and there's probably more I'm not thinking of.
To do this, I think there are a few functional requirements:
- Free up the original executor so that other builds can use it while we're not.
- Somehow "lock" the original workspace so that it doesn't get reused or deleted while we're not on that executor - i.e., we want to make sure another run of the same Pipeline doesn't end up reusing it and instead creates "somePipeline@2" etc.
- Ideally, keep the computer/node the original executor was on from being deleted due to RetentionStrategy until after we've come back to it and are truly done with it. This one is a very-nice-to-have rather than a hard requirement, though - you can work around this by using stash at the end of the stage before you leave the original executor and unstash at the beginning of the stage where you return to that agent/label/whatever. But stash is not very efficient, shall we say.
- In the same vein, make sure we know the specific node/computer the original executor was on so we can return there. However, this is only useful if we've managed to "lock" the workspace to prevent reuse/deletion and we've managed to guarantee the node/computer won't be automatically deleted via a RetentionStrategy before we come back to it. If we can't guarantee reusability of the exact workspace and continued existence of the exact node/computer, knowing exactly where we ran before isn't necessarily of any use.
- We need to decide whether we do this automatically whenever a per-stage agent is specified that does not include reuseNode true (an option on docker and dockerfile agent types) or if we require an additional configuration option (in the agent or on the stage itself) when using any agent but agent none. Usability is fun!
So...yeah. I'm going to try to write up an RFC for this in the next few days, with the hope of getting that approved in the next week or two, followed by implementation in time for Declarative 1.2 (which is tentatively scheduled for late April).
you can also use the node step directly in a stage to get an executor.