Skip to content

Commit 3b3d798

Browse files
rbutcherjetersen
authored andcommitted
Updated changes to support docker.inside in reference to PR-98
1 parent 12f27b0 commit 3b3d798

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ public static class Execution extends AbstractStepExecutionImpl {
151151
throw new AbortException("The docker version is less than v1.7. Pipeline functions requiring 'docker exec' (e.g. 'docker.inside') or SELinux labeling will not work.");
152152
} else if (dockerVersion.isOlderThan(new VersionNumber("1.8"))) {
153153
listener.error("The docker version is less than v1.8. Running a 'docker.inside' from inside a container will not work.");
154+
} else if (dockerVersion.isOlderThan(new VersionNumber("1.13"))) {
155+
if (!launcher.isUnix())
156+
throw new AbortException("The docker version is less than v1.13. Running a 'docker.inside' from inside a Windows container will not work.");
154157
}
155158
} else {
156159
listener.error("Failed to parse docker version. Please note there is a minimum docker version requirement of v1.7.");

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,17 @@ class Docker implements Serializable {
7575
new Image(this, id)
7676
}
7777

78+
String shell() {
79+
node {
80+
script.isUnix() ? "sh" : "bat"
81+
}
82+
}
83+
7884
public Image build(String image, String args = '.') {
7985
node {
8086
def commandLine = "docker build -t ${image} ${args}"
8187

82-
script.sh commandLine
88+
script."${shell()}" commandLine
8389
this.image(image)
8490
}
8591
}
@@ -107,11 +113,11 @@ class Docker implements Serializable {
107113
public <V> V inside(String args = '', Closure<V> body) {
108114
docker.node {
109115
def toRun = imageName()
110-
if (toRun != id && docker.script.sh(script: "docker inspect -f . ${id}", returnStatus: true) == 0) {
116+
if (toRun != id && docker.script."${shell()}"(script: "docker inspect -f . ${id}", returnStatus: true) == 0) {
111117
// Can run it without registry prefix, because it was locally built.
112118
toRun = id
113119
} else {
114-
if (docker.script.sh(script: "docker inspect -f . ${toRun}", returnStatus: true) != 0) {
120+
if (docker.script."${shell()}"(script: "docker inspect -f . ${toRun}", returnStatus: true) != 0) {
115121
// Not yet present locally.
116122
// withDockerContainer requires the image to be available locally, since its start phase is not a durable task.
117123
pull()
@@ -125,13 +131,13 @@ class Docker implements Serializable {
125131

126132
public void pull() {
127133
docker.node {
128-
docker.script.sh "docker pull ${imageName()}"
134+
docker.script."${shell()}" "docker pull ${imageName()}"
129135
}
130136
}
131137

132138
public Container run(String args = '', String command = "") {
133139
docker.node {
134-
def container = docker.script.sh(script: "docker run -d${args != '' ? ' ' + args : ''} ${id}${command != '' ? ' ' + command : ''}", returnStdout: true).trim()
140+
def container = docker.script."${shell()}"(script: "docker run -d${args != '' ? ' ' + args : ''} ${id}${command != '' ? ' ' + command : ''}", returnStdout: true).trim()
135141
new Container(docker, container)
136142
}
137143
}
@@ -150,7 +156,7 @@ class Docker implements Serializable {
150156
public void tag(String tagName = parsedId.tag, boolean force = true) {
151157
docker.node {
152158
def taggedImageName = toQualifiedImageName(parsedId.userAndRepo + ':' + tagName)
153-
docker.script.sh "docker tag ${id} ${taggedImageName}"
159+
docker.script."${shell()}" "docker tag ${id} ${taggedImageName}"
154160
return taggedImageName;
155161
}
156162
}
@@ -160,7 +166,7 @@ class Docker implements Serializable {
160166
// The image may have already been tagged, so the tagging may be a no-op.
161167
// That's ok since tagging is cheap.
162168
def taggedImageName = tag(tagName, force)
163-
docker.script.sh "docker push ${taggedImageName}"
169+
docker.script."${shell()}" "docker push ${taggedImageName}"
164170
}
165171
}
166172

@@ -177,11 +183,11 @@ class Docker implements Serializable {
177183
}
178184

179185
public void stop() {
180-
docker.script.sh "docker stop ${id} && docker rm -f ${id}"
186+
docker.script."${shell()}" "docker stop ${id} && docker rm -f ${id}"
181187
}
182188

183189
public String port(int port) {
184-
docker.script.sh(script: "docker port ${id} ${port}", returnStdout: true).trim()
190+
docker.script."${shell()}"(script: "docker port ${id} ${port}", returnStdout: true).trim()
185191
}
186192
}
187193

0 commit comments

Comments
 (0)