According to jenkins documentation referenced here, to ensure that docker agent defined on a particular stage run on the same node defined in the pipeline, the flag reuseNode must be set to true.
reuseNode A boolean, false by default. If true, run the container on the node specified at the top-level of the Pipeline, in the same workspace, rather than on a new node entirely.This option is valid for docker and dockerfile, and only has an effect when used on an agent for an individual stage.
For declarative this can be achieved using
agent {
docker {
image 'gradle-java:0.0.1'
reuseNode true
}
}
However I am unable to find any example of how to set this in scripted pipelines. Can somebody help with how to achieve this in scripted pipelines?