Restart agent for each build How do I configure jenkins to restart the agent for each build?

I tried to use "launch method: launch agent via execution of command on the master" in combintation with "availability: take this agent online when in demand, and offline when idle" but it has two drawbacks:


(not critical) build starts with a delay of about one minute.
(critical) the node goes offline only a minute after the end of the build, and if another build starts at that time, the same still running agent will be used (even if there are several similarly configured free nodes).


There is even a plugin (scripted cloud plugin) that, according to the description, should be suitable, but it does not work, probably because its code is outdated.
Slave restarts the agent itself after each build? You can use Conditional BuildStep plugin to restart it on a defined condition.