Skip to content

Commit eb0b0db

Browse files
authored
Add ability to skip removal of container after docker stop (jenkinsci#189)
Co-authored-by: Jon Sten <[email protected]>
1 parent 04719f7 commit eb0b0db

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main/java/org/jenkinsci/plugins/docker/workflow/client/DockerClient.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ public class DockerClient {
7676
@Restricted(NoExternalUse.class)
7777
public static int CLIENT_TIMEOUT = Integer.getInteger(DockerClient.class.getName() + ".CLIENT_TIMEOUT", 180); // TODO 2.4+ SystemProperties
7878

79+
/**
80+
* Skip removal of container after a container has been stopped.
81+
*/
82+
@SuppressFBWarnings(value="MS_SHOULD_BE_FINAL", justification="mutable for scripts")
83+
@Restricted(NoExternalUse.class)
84+
public static boolean SKIP_RM_ON_STOP = Boolean.getBoolean(DockerClient.class.getName() + ".SKIP_RM_ON_STOP");
85+
7986
// e.g. 2015-04-09T13:40:21.981801679Z
8087
public static final String DOCKER_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
8188

@@ -165,7 +172,8 @@ public List<String> listProcess(@Nonnull EnvVars launchEnv, @Nonnull String cont
165172
* Stop a container.
166173
*
167174
* <p>
168-
* Also removes ({@link #rm(EnvVars, String)}) the container.
175+
* Also removes ({@link #rm(EnvVars, String)}) the container if property
176+
* SKIP_RM_ON_STOP is unset or equals false.
169177
*
170178
* @param launchEnv Docker client launch environment.
171179
* @param containerId The container ID.
@@ -175,7 +183,9 @@ public void stop(@Nonnull EnvVars launchEnv, @Nonnull String containerId) throws
175183
if (result.getStatus() != 0) {
176184
throw new IOException(String.format("Failed to kill container '%s'.", containerId));
177185
}
178-
rm(launchEnv, containerId);
186+
if (!SKIP_RM_ON_STOP) {
187+
rm(launchEnv, containerId);
188+
}
179189
}
180190

181191
/**

0 commit comments

Comments
 (0)