|
4 | 4 | import static org.hamcrest.Matchers.*;
|
5 | 5 |
|
6 | 6 | import hudson.model.Result;
|
| 7 | +import hudson.model.labels.LabelAtom; |
7 | 8 | import hudson.model.queue.QueueTaskFuture;
|
| 9 | +import hudson.slaves.DumbSlave; |
8 | 10 | import io.jenkins.plugins.pipelinegraphview.treescanner.NodeRelationshipFinder;
|
9 | 11 | import io.jenkins.plugins.pipelinegraphview.treescanner.PipelineNodeGraphAdapter;
|
10 | 12 | import io.jenkins.plugins.pipelinegraphview.treescanner.PipelineNodeTreeScanner;
|
@@ -408,4 +410,76 @@ public void gh_358_parallelStagesMarkedAsSkipped() throws Exception {
|
408 | 410 | equalTo(
|
409 | 411 | "foo{success},first-parallel{failure}[bar{skipped},baz{failure}],second-parallel{skipped},Post Actions{success}"));
|
410 | 412 | }
|
| 413 | + |
| 414 | + @Test |
| 415 | + public void getAgentForSingleStagePipeline() throws Exception { |
| 416 | + WorkflowRun run = TestUtils.createAndRunJob( |
| 417 | + j, "getAgentForSingleStagePipeline", "singleStagePipeline.jenkinsfile", Result.SUCCESS); |
| 418 | + |
| 419 | + List<PipelineStage> stages = new PipelineGraphApi(run).createTree().getStages(); |
| 420 | + |
| 421 | + assertThat(stages.size(), equalTo(1)); |
| 422 | + assertThat(stages.get(0).getAgent(), equalTo("built-in")); |
| 423 | + } |
| 424 | + |
| 425 | + @Test |
| 426 | + public void getAgentForSingleStagePipelineWithExternalAgent() throws Exception { |
| 427 | + var testingLabel = new LabelAtom("external"); |
| 428 | + DumbSlave agent = j.createSlave(testingLabel); |
| 429 | + j.waitOnline(agent); |
| 430 | + |
| 431 | + WorkflowRun run = TestUtils.createAndRunJob( |
| 432 | + j, |
| 433 | + "getAgentForSingleStagePipelineWithExternalAgent", |
| 434 | + "singleStagePipelineWithExternalAgent.jenkinsfile", |
| 435 | + Result.SUCCESS); |
| 436 | + |
| 437 | + List<PipelineStage> stages = new PipelineGraphApi(run).createTree().getStages(); |
| 438 | + |
| 439 | + assertThat(stages.size(), equalTo(1)); |
| 440 | + assertThat(stages.get(0).getAgent(), equalTo(agent.getNodeName())); |
| 441 | + } |
| 442 | + |
| 443 | + @Test |
| 444 | + public void getAgentForParallelPipelineWithExternalAgent() throws Exception { |
| 445 | + var testingLabel = new LabelAtom("external"); |
| 446 | + DumbSlave agent = j.createSlave(testingLabel); |
| 447 | + j.waitOnline(agent); |
| 448 | + |
| 449 | + WorkflowRun run = TestUtils.createAndRunJob( |
| 450 | + j, |
| 451 | + "getAgentForParallelPipelineWithExternalAgent", |
| 452 | + "parallelPipelineWithExternalAgent.jenkinsfile", |
| 453 | + Result.SUCCESS); |
| 454 | + |
| 455 | + List<PipelineStage> stages = new PipelineGraphApi(run).createTree().getStages(); |
| 456 | + |
| 457 | + // Parallel pipeline structure: |
| 458 | + // name: Parallel, type: STAGE |
| 459 | + // name: Parallel, type: PARALLEL_BLOCK |
| 460 | + |
| 461 | + // name: Builtin, type: PARALLEL |
| 462 | + // name: Stage : Start, type: STEPS_BLOCK |
| 463 | + // name: Builtin, type: STAGE |
| 464 | + // name: Allocate node : Start, type: STEPS_BLOCK |
| 465 | + |
| 466 | + assertThat(stages.size(), equalTo(1)); |
| 467 | + assertThat(stages.get(0).getType(), equalTo("STAGE")); |
| 468 | + assertThat(stages.get(0).getName(), equalTo("Parallel")); |
| 469 | + assertThat(stages.get(0).getAgent(), equalTo(null)); |
| 470 | + |
| 471 | + List<PipelineStage> children = stages.get(0).getChildren(); |
| 472 | + |
| 473 | + assertThat(children.size(), equalTo(2)); |
| 474 | + |
| 475 | + PipelineStage builtinStage = children.get(0); |
| 476 | + assertThat(builtinStage.getType(), equalTo("PARALLEL")); |
| 477 | + assertThat(builtinStage.getName(), equalTo("Builtin")); |
| 478 | + assertThat(builtinStage.getAgent(), equalTo("built-in")); |
| 479 | + |
| 480 | + PipelineStage externalStage = children.get(1); |
| 481 | + assertThat(externalStage.getType(), equalTo("PARALLEL")); |
| 482 | + assertThat(externalStage.getName(), equalTo("External")); |
| 483 | + assertThat(externalStage.getAgent(), equalTo(agent.getNodeName())); |
| 484 | + } |
411 | 485 | }
|
0 commit comments