Skip to content

Commit f558f83

Browse files
authored
Merge branch 'master' into CustomDescribableModel-JENKINS-44892
2 parents 0aa01cb + 129a2d7 commit f558f83

File tree

13 files changed

+126
-56
lines changed

13 files changed

+126
-56
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
version: 2
22
updates:
3-
- package-ecosystem: "maven"
4-
directory: "/"
5-
schedule:
6-
interval: "weekly"
3+
- package-ecosystem: maven
4+
directory: /
5+
schedule:
6+
interval: monthly
7+
- package-ecosystem: github-actions
8+
directory: /
9+
schedule:
10+
interval: monthly

.github/release-drafter.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/cd.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Note: additional setup is required, see https://www.jenkins.io/redirect/continuous-delivery-of-plugins
2+
3+
name: cd
4+
on:
5+
workflow_dispatch:
6+
check_run:
7+
types:
8+
- completed
9+
10+
jobs:
11+
maven-cd:
12+
uses: jenkins-infra/github-reusable-workflows/.github/workflows/maven-cd.yml@v1
13+
secrets:
14+
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
15+
MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }}

.github/workflows/release-drafter.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.mvn/extensions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<extension>
33
<groupId>io.jenkins.tools.incrementals</groupId>
44
<artifactId>git-changelist-maven-extension</artifactId>
5-
<version>1.3</version>
5+
<version>1.4</version>
66
</extension>
77
</extensions>

.mvn/maven.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
-Pconsume-incrementals
22
-Pmight-produce-incrementals
3+
-Dchangelist.format=%d.v%s

pom.xml

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<parent>
55
<groupId>org.jenkins-ci.plugins</groupId>
66
<artifactId>plugin</artifactId>
7-
<version>4.12</version>
7+
<version>4.51</version>
88
<relativePath />
99
</parent>
1010
<artifactId>docker-workflow</artifactId>
11-
<version>${revision}${changelist}</version>
11+
<version>${changelist}</version>
1212
<name>Docker Pipeline</name>
1313
<description>Build and use Docker containers from pipelines</description>
1414
<packaging>hpi</packaging>
@@ -20,20 +20,18 @@
2020
</license>
2121
</licenses>
2222

23-
<url>https://github.com/jenkinsci/docker-workflow-plugin</url>
23+
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
2424
<scm>
25-
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
26-
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
27-
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
25+
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
26+
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
27+
<url>https://github.com/${gitHubRepo}</url>
2828
<tag>${scmTag}</tag>
2929
</scm>
3030

3131
<properties>
32-
<revision>1.30</revision>
33-
<changelist>-SNAPSHOT</changelist>
34-
<jenkins.version>2.332.1</jenkins.version>
35-
<java.level>8</java.level>
36-
<pipeline-model-definition-plugin.version>2.2097.v33db_b_de764b_e</pipeline-model-definition-plugin.version> <!-- TODO: Delete this and related dependencyManagement entries once this version is included in BOM -->
32+
<changelist>999999-SNAPSHOT</changelist>
33+
<jenkins.version>2.332.1</jenkins.version>
34+
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
3735
</properties>
3836
<repositories>
3937
<repository>
@@ -52,32 +50,29 @@
5250
<dependency>
5351
<groupId>io.jenkins.tools.bom</groupId>
5452
<artifactId>bom-2.332.x</artifactId>
55-
<version>1409.v7659b_c072f18</version>
53+
<version>1643.v1cffef51df73</version>
5654
<scope>import</scope>
5755
<type>pom</type>
5856
</dependency>
5957
<dependency>
6058
<groupId>org.jenkinsci.plugins</groupId>
61-
<artifactId>pipeline-model-api</artifactId>
62-
<version>${pipeline-model-definition-plugin.version}</version>
59+
<artifactId>pipeline-model-api</artifactId>
6360
</dependency>
6461
<dependency>
6562
<groupId>org.jenkinsci.plugins</groupId>
66-
<artifactId>pipeline-model-extensions</artifactId>
67-
<version>${pipeline-model-definition-plugin.version}</version>
63+
<artifactId>pipeline-model-extensions</artifactId>
6864
</dependency>
6965
<dependency>
7066
<groupId>org.jenkinsci.plugins</groupId>
71-
<artifactId>pipeline-stage-tags-metadata</artifactId>
72-
<version>${pipeline-model-definition-plugin.version}</version>
67+
<artifactId>pipeline-stage-tags-metadata</artifactId>
7368
</dependency>
7469
</dependencies>
7570
</dependencyManagement>
7671
<dependencies>
7772
<dependency>
7873
<groupId>org.jenkins-ci.plugins</groupId>
7974
<artifactId>docker-commons</artifactId>
80-
<version>1.19</version>
75+
<version>1.21</version>
8176
</dependency>
8277
<dependency>
8378
<groupId>org.jenkins-ci.plugins.workflow</groupId>
@@ -135,7 +130,6 @@
135130
<dependency>
136131
<groupId>org.jenkinsci.plugins</groupId>
137132
<artifactId>pipeline-model-definition</artifactId>
138-
<version>${pipeline-model-definition-plugin.version}</version>
139133
</dependency>
140134
<dependency>
141135
<groupId>org.jenkins-ci.plugins</groupId>
@@ -157,7 +151,6 @@
157151
<dependency>
158152
<groupId>org.jenkinsci.plugins</groupId>
159153
<artifactId>pipeline-model-definition</artifactId>
160-
<version>${pipeline-model-definition-plugin.version}</version>
161154
<classifier>tests</classifier>
162155
<scope>test</scope>
163156
</dependency>

src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public String getToolName() {
107107
this.toolName = Util.fixEmpty(toolName);
108108
}
109109

110-
private static void destroy(String container, Launcher launcher, Node node, EnvVars launcherEnv, String toolName) throws Exception {
110+
private static void destroy(String container, @NonNull Launcher launcher, Node node, EnvVars launcherEnv, String toolName) throws Exception {
111111
new DockerClient(launcher, node, toolName).stop(launcherEnv, container);
112112
}
113113

@@ -410,7 +410,10 @@ private static class Callback extends BodyExecutionCallback.TailCall {
410410
}
411411

412412
@Override protected void finished(StepContext context) throws Exception {
413-
destroy(container, context.get(Launcher.class), context.get(Node.class), context.get(EnvVars.class), toolName);
413+
Launcher launcher = context.get(Launcher.class);
414+
if (launcher != null) {
415+
destroy(container, launcher, context.get(Node.class), context.get(EnvVars.class), toolName);
416+
}
414417
}
415418

416419
}

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@
3636
import java.io.BufferedReader;
3737
import java.io.ByteArrayOutputStream;
3838
import java.io.IOException;
39+
import java.io.InputStream;
40+
import java.io.InputStreamReader;
3941
import java.io.Reader;
4042
import java.io.StringReader;
4143
import java.nio.charset.Charset;
44+
import java.nio.charset.StandardCharsets;
4245
import java.text.ParseException;
4346
import java.text.SimpleDateFormat;
4447
import java.util.ArrayList;
@@ -196,7 +199,7 @@ public void stop(@NonNull EnvVars launchEnv, @NonNull String containerId) throws
196199
*/
197200
public void rm(@NonNull EnvVars launchEnv, @NonNull String containerId) throws IOException, InterruptedException {
198201
LaunchResult result;
199-
result = launch(launchEnv, false, "rm", "-f", containerId);
202+
result = launch(launchEnv, false, "rm", "-f", "--volumes", containerId);
200203
if (result.getStatus() != 0) {
201204
throw new IOException(String.format("Failed to rm container '%s'.", containerId));
202205
}
@@ -336,6 +339,8 @@ public String whoAmI() throws IOException, InterruptedException {
336339

337340
}
338341

342+
private static final Pattern hostnameMount = Pattern.compile("/containers/([a-z0-9]{64})/hostname");
343+
339344
/**
340345
* Checks if this {@link DockerClient} instance is running inside a container and returns the id of the container
341346
* if so.
@@ -349,10 +354,26 @@ public Optional<String> getContainerIdIfContainerized() throws IOException, Inte
349354
return Optional.absent();
350355
}
351356
FilePath cgroupFile = node.createPath("/proc/self/cgroup");
352-
if (cgroupFile == null || !cgroupFile.exists()) {
353-
return Optional.absent();
357+
if (cgroupFile != null && cgroupFile.exists()) {
358+
Optional<String> containerId = ControlGroup.getContainerId(cgroupFile);
359+
if (containerId.isPresent()) {
360+
return containerId;
361+
}
362+
}
363+
// cgroup v2
364+
FilePath mountInfo = node.createPath("/proc/1/mountinfo");
365+
if (mountInfo != null && mountInfo.exists()) {
366+
try (InputStream is = mountInfo.read(); Reader r = new InputStreamReader(is, StandardCharsets.UTF_8); BufferedReader br = new BufferedReader(r)) {
367+
String line;
368+
while ((line = br.readLine()) != null) {
369+
Matcher m = hostnameMount.matcher(line);
370+
if (m.find()) {
371+
return Optional.of(m.group(1));
372+
}
373+
}
374+
}
354375
}
355-
return ControlGroup.getContainerId(cgroupFile);
376+
return Optional.absent();
356377
}
357378

358379
public ContainerRecord getContainerRecord(@NonNull EnvVars launchEnv, String containerId) throws IOException, InterruptedException {

src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class Docker implements Serializable {
211211

212212
public void stop() {
213213
docker.script.withEnv(["JD_ID=${id}"]) {
214-
docker.script."${docker.shell(isUnix)}" 'docker stop "' + docker.asEnv(isUnix,'JD_ID') + '" && docker rm -f "' + docker.asEnv(isUnix, 'JD_ID') + '"'
214+
docker.script."${docker.shell(isUnix)}" 'docker stop "' + docker.asEnv(isUnix,'JD_ID') + '" && docker rm -f --volumes "' + docker.asEnv(isUnix, 'JD_ID') + '"'
215215
}
216216
}
217217

0 commit comments

Comments
 (0)