diff --git a/core/src/main/java/hudson/model/LoadBalancer.java b/core/src/main/java/hudson/model/LoadBalancer.java index a0403e1b97..ce69e89779 100644 --- a/core/src/main/java/hudson/model/LoadBalancer.java +++ b/core/src/main/java/hudson/model/LoadBalancer.java @@ -112,7 +112,7 @@ public abstract class LoadBalancer implements ExtensionPoint { private boolean assignGreedily(Mapping m, Task task, List> hashes, int i) { if (i==hashes.size()) return true; // fully assigned - String key = task.getFullDisplayName() + (i>0 ? String.valueOf(i) : ""); + String key = task.getAffinityKey() + (i>0 ? String.valueOf(i) : ""); for (ExecutorChunk ec : hashes.get(i).list(key)) { // let's attempt this assignment diff --git a/core/src/main/java/hudson/model/Queue.java b/core/src/main/java/hudson/model/Queue.java index 01a43ea299..1eaeb08931 100644 --- a/core/src/main/java/hudson/model/Queue.java +++ b/core/src/main/java/hudson/model/Queue.java @@ -1896,6 +1896,18 @@ public class Queue extends ResourceController implements Saveable { */ String getFullDisplayName(); + /** + * Returns task-specific key which is used by the {@link LoadBalancer} to choose one particular executor + * amongst all the free executors on all possibly suitable nodes. + * NOTE: To be able to re-use the same node during the next run this key should not change from one run to + * another. You probably want to compute that key based on the job's name. + *

+ * @return by default: {@link #getFullDisplayName()} + * + * @see hudson.model.LoadBalancer + */ + default String getAffinityKey() { return getFullDisplayName(); } + /** * Checks the permission to see if the current user can abort this executable. * Returns normally from this method if it's OK.