|
25 | 25 |
|
26 | 26 | import static org.jenkinsci.plugins.docker.workflow.DockerTestUtil.assumeDocker;
|
27 | 27 |
|
| 28 | +import hudson.util.VersionNumber; |
28 | 29 | import org.jenkinsci.plugins.docker.workflow.client.DockerClient;
|
29 | 30 | import hudson.EnvVars;
|
30 | 31 | import hudson.Launcher;
|
@@ -325,6 +326,47 @@ private static void grep(File dir, String text, String prefix, Set<String> match
|
325 | 326 | });
|
326 | 327 | }
|
327 | 328 |
|
| 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 | + |
328 | 370 | @Test public void buildArguments() {
|
329 | 371 | story.addStep(new Statement() {
|
330 | 372 | @Override public void evaluate() throws Throwable {
|
|
0 commit comments