Skip to content

Commit b8f7c60

Browse files
authored
Merge pull request jenkinsci#111 from ericsmalling/master
[FIXED JENKINS-44609] Docker multi-stage builds no longer throw errors
2 parents 111b78e + abf877d commit b8f7c60

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static class Execution extends AbstractSynchronousNonBlockingStepExecutio
9999
}
100100
if (line.startsWith("FROM ")) {
101101
fromImage = line.substring(5);
102-
break;
102+
continue;
103103
}
104104
}
105105
} finally {

src/test/java/org/jenkinsci/plugins/docker/workflow/DockerDSLTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import static org.jenkinsci.plugins.docker.workflow.DockerTestUtil.assumeDocker;
2727

28+
import hudson.util.VersionNumber;
2829
import org.jenkinsci.plugins.docker.workflow.client.DockerClient;
2930
import hudson.EnvVars;
3031
import hudson.Launcher;
@@ -325,6 +326,47 @@ private static void grep(File dir, String text, String prefix, Set<String> match
325326
});
326327
}
327328

329+
@Test public void buildWithMultiStage() {
330+
story.addStep(new Statement() {
331+
@Override public void evaluate() throws Throwable {
332+
assumeDocker(new VersionNumber("17.05"));
333+
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj");
334+
p.setDefinition(new CpsFlowDefinition(
335+
"node {\n" +
336+
" sh 'mkdir -p child'\n" +
337+
" writeFile file: 'child/stuff1', text: 'hello'\n" +
338+
" writeFile file: 'child/stuff2', text: 'world'\n" +
339+
" writeFile file: 'child/stuff3', text: env.BUILD_NUMBER\n" +
340+
" writeFile file: 'child/Dockerfile.other', " +
341+
"text: '# This is a test.\\n" +
342+
"\\n" +
343+
"FROM hello-world AS one\\n" +
344+
"ARG stuff4=4\\n" +
345+
"ARG stuff5=5\\n" +
346+
"COPY stuff1 /\\n" +
347+
"FROM scratch\\n" +
348+
"COPY --from=one /stuff1 /\\n" +
349+
"COPY stuff2 /\\nCOPY stuff3 /\\n'\n" +
350+
" def built = docker.build 'hello-world-stuff-arguments', '-f child/Dockerfile.other --build-arg stuff4=build4 --build-arg stuff5=build5 child'\n" +
351+
" echo \"built ${built.id}\"\n" +
352+
"}", true));
353+
354+
// Note the absence '--pull' in the above docker build ags as compared to other tests.
355+
// This is due to a Docker bug: https://github.com/docker/for-mac/issues/1751
356+
// It can be re-added when that is fixed
357+
358+
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
359+
DockerClient client = new DockerClient(new Launcher.LocalLauncher(StreamTaskListener.NULL), null, null);
360+
String descendantImageId1 = client.inspect(new EnvVars(), "hello-world-stuff-arguments", ".Id");
361+
story.j.assertLogContains("built hello-world-stuff-arguments", b);
362+
story.j.assertLogNotContains(" --no-cache ", b);
363+
story.j.assertLogContains(descendantImageId1.replaceFirst("^sha256:", "").substring(0, 12), b);
364+
story.j.assertLogContains(" --build-arg stuff4=build4 ", b);
365+
story.j.assertLogContains(" --build-arg stuff5=build5 ", b);
366+
}
367+
});
368+
}
369+
328370
@Test public void buildArguments() {
329371
story.addStep(new Statement() {
330372
@Override public void evaluate() throws Throwable {

src/test/java/org/jenkinsci/plugins/docker/workflow/DockerTestUtil.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,21 @@
3939
* @author <a href="mailto:[email protected]">[email protected]</a>
4040
*/
4141
public class DockerTestUtil {
42-
42+
public static String DEFAULT_MINIMUM_VERSION = "1.3";
43+
4344
public static void assumeDocker() throws Exception {
45+
assumeDocker(new VersionNumber(DEFAULT_MINIMUM_VERSION));
46+
}
47+
48+
public static void assumeDocker(VersionNumber minimumVersion) throws Exception {
4449
Launcher.LocalLauncher localLauncher = new Launcher.LocalLauncher(StreamTaskListener.NULL);
4550
try {
4651
Assume.assumeThat("Docker working", localLauncher.launch().cmds(DockerTool.getExecutable(null, null, null, null), "ps").start().joinWithTimeout(DockerClient.CLIENT_TIMEOUT, TimeUnit.SECONDS, localLauncher.getListener()), is(0));
4752
} catch (IOException x) {
4853
Assume.assumeNoException("have Docker installed", x);
4954
}
5055
DockerClient dockerClient = new DockerClient(localLauncher, null, null);
51-
Assume.assumeFalse("Docker version not < 1.3", dockerClient.version().isOlderThan(new VersionNumber("1.3")));
56+
Assume.assumeFalse("Docker version not < " + minimumVersion.toString(), dockerClient.version().isOlderThan(minimumVersion));
5257
}
5358

5459
private DockerTestUtil() {}

0 commit comments

Comments
 (0)