From 630f506d0c686feb5f73d2bf7fc7b6579b004742 Mon Sep 17 00:00:00 2001 From: David-Villeneuve <25620250+David-Villeneuve@users.noreply.github.com> Date: Fri, 5 Nov 2021 10:07:43 -0400 Subject: [PATCH] Prevent premature removal of agent when Jenkins is in quiet mode Issue: https://github.com/jenkinsci/docker-swarm-plugin/issues/113 --- .../docker/swarm/DockerSwarmAgentRetentionStrategy.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentRetentionStrategy.java b/src/main/java/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentRetentionStrategy.java index 31e4878..41cc23d 100644 --- a/src/main/java/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentRetentionStrategy.java +++ b/src/main/java/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentRetentionStrategy.java @@ -19,6 +19,7 @@ import hudson.model.ExecutorListener; import hudson.model.Queue; import hudson.slaves.RetentionStrategy; +import jenkins.model.Jenkins; public class DockerSwarmAgentRetentionStrategy extends RetentionStrategy implements ExecutorListener { @@ -45,7 +46,7 @@ public long check(@Nonnull DockerSwarmComputer c) { final long connectTime = System.currentTimeMillis() - c.getConnectTime(); final long idleTime = System.currentTimeMillis() - c.getIdleStartMilliseconds(); final boolean isTimeout = connectTime > timeout && idleTime > timeout; - if (isTimeout && (!isTaskAccepted || isTaskCompleted)) { + if (isTimeout && (!isTaskAccepted || isTaskCompleted ) && !Jenkins.getInstance().isQuietingDown()) { LOGGER.log(Level.INFO, "Disconnecting due to idle {0}", c.getName()); done(c); }