if (execution != null) { DepthFirstScanner scanner = new DepthFirstScanner(); FlowNode stageId = scanner.findFirstMatch(execution, new StageNamePredicate(stageName)); if (stageId != null) { tr = ((hudson.tasks.junit.TestResult) tr).getResultForPipelineBlock(stageId.getId());
private void assertStageIsNotExecuted(@Nonnull String stageName, @Nonnull WorkflowRun run, @Nonnull FlowExecution execution) { List<FlowNode> heads = execution.getCurrentHeads(); DepthFirstScanner scanner = new DepthFirstScanner(); FlowNode startStage = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName(stageName)); assertNotNull(startStage); assertTrue(startStage instanceof BlockStartNode); FlowNode endStage = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startStage)); assertNotNull(endStage); assertEquals(GenericStatus.NOT_EXECUTED, StatusAndTiming.computeChunkStatus(run, null, startStage, endStage, null)); } }
public static void assertStageResults(WorkflowRun run, int suiteCount, int testCount, int failCount, String stageName) { FlowExecution execution = run.getExecution(); DepthFirstScanner scanner = new DepthFirstScanner(); FlowNode aStage = scanner.findFirstMatch(execution, stageForName(stageName)); assertNotNull(aStage); assertBlockResults(run, suiteCount, testCount, failCount, aStage); }
@Test public void skippedStagesForFailure() throws Exception { WorkflowRun b = expect(Result.FAILURE, "skippedStagesForFailure") .logContains("[Pipeline] { (foo)", "hello", "I have failed") .logNotContains("I will be skipped", "I also will be skipped", "I have succeeded") .go(); FlowExecution execution = b.getExecution(); assertNotNull(execution); assertNotNull(execution.getCauseOfFailure()); Collection<FlowNode> heads = execution.getCurrentHeads(); DepthFirstScanner scanner = new DepthFirstScanner(); assertNull(scanner.findFirstMatch(heads, stageStatusPredicate("foo", Utils.getStageStatusMetadata().getSkippedForFailure()))); assertNotNull(scanner.findFirstMatch(heads, stageStatusPredicate("foo", Utils.getStageStatusMetadata().getFailedAndContinued()))); assertNotNull(scanner.findFirstMatch(heads, stageStatusPredicate("bar", Utils.getStageStatusMetadata().getSkippedForFailure()))); assertNotNull(scanner.findFirstMatch(heads, stageStatusPredicate("baz", Utils.getStageStatusMetadata().getSkippedForFailure()))); }
FlowExecution execution = owner.get(); if (execution != null) { previousHadStep = new DepthFirstScanner().findFirstMatch(execution, new NodeStepTypePredicate(step.getDescriptor())) != null;
FlowExecution execution = owner.getOrNull(); if (execution != null) { previousHadStep = new DepthFirstScanner().findFirstMatch(execution, new NodeStepTypePredicate(step.getDescriptor())) != null;
@Test public void noToolSyntheticStage() throws Exception { WorkflowRun b = expect("noToolSyntheticStage") .logContains("[Pipeline] { (" + SyntheticStageNames.checkout() + ")", "[Pipeline] { (foo)", "hello", "[Pipeline] { (" + SyntheticStageNames.postBuild() + ")", "I AM A POST-BUILD") .go(); FlowExecution execution = b.getExecution(); assertNotNull(execution); Collection<FlowNode> heads = execution.getCurrentHeads(); DepthFirstScanner scanner = new DepthFirstScanner(); assertNull(scanner.findFirstMatch(heads, null, syntheticStagePredicate(SyntheticStageNames.toolInstall(), Utils.getSyntheticStageMetadata().getPre()))); assertNotNull(scanner.findFirstMatch(heads, null, syntheticStagePredicate(SyntheticStageNames.checkout(), Utils.getSyntheticStageMetadata().getPre()))); assertNotNull(scanner.findFirstMatch(heads, null, syntheticStagePredicate(SyntheticStageNames.postBuild(), Utils.getSyntheticStageMetadata().getPost()))); assertNull(scanner.findFirstMatch(heads, null, syntheticStagePredicate(SyntheticStageNames.agentSetup(), Utils.getSyntheticStageMetadata().getPre()))); }
@Test public void syntheticStages() throws Exception { WorkflowRun b = expect("syntheticStages") .logContains("[Pipeline] { (" + SyntheticStageNames.toolInstall() + ")", "[Pipeline] { (" + SyntheticStageNames.checkout() + ")", "[Pipeline] { (foo)", "hello", "[Pipeline] { (" + SyntheticStageNames.postBuild() + ")", "I AM A POST-BUILD") .go(); FlowExecution execution = b.getExecution(); assertNotNull(execution); Collection<FlowNode> heads = execution.getCurrentHeads(); DepthFirstScanner scanner = new DepthFirstScanner(); assertNotNull(scanner.findFirstMatch(heads, null, syntheticStagePredicate(SyntheticStageNames.toolInstall(), Utils.getSyntheticStageMetadata().getPre()))); assertNotNull(scanner.findFirstMatch(heads, null, syntheticStagePredicate(SyntheticStageNames.checkout(), Utils.getSyntheticStageMetadata().getPre()))); assertNotNull(scanner.findFirstMatch(heads, null, syntheticStagePredicate(SyntheticStageNames.postBuild(), Utils.getSyntheticStageMetadata().getPost()))); assertNull(scanner.findFirstMatch(heads, null, syntheticStagePredicate(SyntheticStageNames.agentSetup(), Utils.getSyntheticStageMetadata().getPre()))); }
@Issue("JENKINS-42039") @Test public void skipAfterUnstableWithOption() throws Exception { WorkflowRun b = expect(Result.UNSTABLE, "skipAfterUnstableIfOption") .logContains("[Pipeline] { (foo)", "hello", "[Pipeline] { (bar)") .logNotContains("goodbye") .go(); FlowExecution execution = b.getExecution(); assertNotNull(execution); List<FlowNode> heads = execution.getCurrentHeads(); DepthFirstScanner scanner = new DepthFirstScanner(); FlowNode startFoo = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("foo")); assertNotNull(startFoo); assertTrue(startFoo instanceof StepStartNode); FlowNode endFoo = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((StepStartNode)startFoo)); assertNotNull(endFoo); assertEquals(GenericStatus.UNSTABLE, StatusAndTiming.computeChunkStatus(b, null, startFoo, endFoo, null)); }
public static void assertBranchResults(WorkflowRun run, int suiteCount, int testCount, int failCount, String branchName, String stageName, String innerStageName) { FlowExecution execution = run.getExecution(); DepthFirstScanner scanner = new DepthFirstScanner(); FlowNode aBranch = scanner.findFirstMatch(execution, branchForName(branchName)); assertNotNull(aBranch); TestResult branchResult = assertBlockResults(run, suiteCount, testCount, failCount, aBranch); String namePrefix = stageName + " / " + branchName; if (innerStageName != null) { namePrefix += " / " + innerStageName; } for (CaseResult c : branchResult.getPassedTests()) { assertEquals(namePrefix + " / " + c.getTransformedTestName(), c.getDisplayName()); } }
List<FlowNode> heads = execution.getCurrentHeads(); DepthFirstScanner scanner = new DepthFirstScanner(); FlowNode startFoo = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("foo")); assertNotNull(startFoo); assertTrue(startFoo instanceof BlockStartNode); FlowNode endFoo = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startFoo)); assertNotNull(endFoo); assertEquals(GenericStatus.FAILURE, StatusAndTiming.computeChunkStatus(b, null, startFoo, endFoo, null)); assertNotNull(endFoo.getError()); FlowNode startFirst = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("first")); assertNotNull(startFirst); assertTrue(startFirst instanceof BlockStartNode); FlowNode endFirst = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startFirst)); assertNotNull(endFirst); assertEquals(GenericStatus.FAILURE, StatusAndTiming.computeChunkStatus(b, null, startFirst, endFirst, null)); FlowNode startSecond = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("second")); assertNotNull(startSecond); assertTrue(startSecond instanceof BlockStartNode); FlowNode endSecond = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startSecond)); assertNotNull(endSecond); assertEquals(GenericStatus.FAILURE, StatusAndTiming.computeChunkStatus(b, null, startSecond, endSecond, null));
List<FlowNode> heads = execution.getCurrentHeads(); DepthFirstScanner scanner = new DepthFirstScanner(); FlowNode startFoo = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("foo")); assertNotNull(startFoo); assertTrue(startFoo instanceof BlockStartNode); FlowNode endFoo = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startFoo)); assertNotNull(endFoo); assertEquals(GenericStatus.SUCCESS, StatusAndTiming.computeChunkStatus(b, null, startFoo, endFoo, null)); assertNull(endFoo.getError()); FlowNode startFirst = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("first")); assertNotNull(startFirst); assertTrue(startFirst instanceof BlockStartNode); FlowNode endFirst = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startFirst)); assertNotNull(endFirst); assertEquals(GenericStatus.SUCCESS, StatusAndTiming.computeChunkStatus(b, null, startFirst, endFirst, null)); FlowNode startInnerFirst = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("inner-first")); assertNotNull(startInnerFirst); assertTrue(startInnerFirst instanceof BlockStartNode); FlowNode endInnerFirst = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startInnerFirst)); assertNotNull(endInnerFirst); assertEquals(GenericStatus.SUCCESS, StatusAndTiming.computeChunkStatus(b, null, startInnerFirst, endInnerFirst, null)); FlowNode startInnerSecond = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("inner-second")); assertNotNull(startInnerSecond); assertTrue(startInnerSecond instanceof BlockStartNode); FlowNode endInnerSecond = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startInnerSecond)); assertNotNull(endInnerSecond);
FlowExecution execution = r.getExecution(); DepthFirstScanner scanner = new DepthFirstScanner(); FlowNode f = scanner.findFirstMatch(execution, new Predicate<FlowNode>() { @Override public boolean apply(@Nullable FlowNode input) {
@Issue("JENKINS-38097") @Test public void allStagesExist() throws Exception { WorkflowRun b = expect(Result.FAILURE, "allStagesExist") .logContains("[Pipeline] { (foo)", "hello", "[Pipeline] { (bar)") .hasFailureCase() .go(); FlowExecution execution = b.getExecution(); assertNotNull(execution); List<FlowNode> heads = execution.getCurrentHeads(); DepthFirstScanner scanner = new DepthFirstScanner(); FlowNode startFoo = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("foo")); assertNotNull(startFoo); assertTrue(startFoo instanceof StepStartNode); FlowNode endFoo = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((StepStartNode)startFoo)); assertNotNull(endFoo); assertEquals(GenericStatus.FAILURE, StatusAndTiming.computeChunkStatus(b, null, startFoo, endFoo, null)); assertNotNull(endFoo.getError()); FlowNode shouldBeFailedNode = execution.getNode("" + (Integer.valueOf(endFoo.getId()) - 1)); assertNotNull(shouldBeFailedNode); assertNotNull(shouldBeFailedNode.getError()); TagsAction parentTags = startFoo.getAction(TagsAction.class); assertNotNull(parentTags); assertNotNull(parentTags.getTags()); assertFalse(parentTags.getTags().isEmpty()); assertTrue(parentTags.getTags().containsKey(Utils.getStageStatusMetadata().getTagName())); assertEquals(Utils.getStageStatusMetadata().getFailedAndContinued(), parentTags.getTags().get(Utils.getStageStatusMetadata().getTagName())); }
@Ignore("No longer relevant due to https://github.com/jenkinsci/workflow-support-plugin/commit/d5d1f46255b623587198a25f8c179c64f0b74d12") @Issue("JENKINS-46112") @Test public void logActionPresentForError() throws Exception { WorkflowRun r = expect(Result.FAILURE, "logActionPresentForError").go(); FlowExecution execution = r.getExecution(); assertNotNull(execution); Collection<FlowNode> heads = execution.getCurrentHeads(); DepthFirstScanner scanner = new DepthFirstScanner(); FlowNode n = scanner.findFirstMatch(heads, null, new Predicate<FlowNode>() { @Override public boolean apply(FlowNode input) { return input instanceof StepAtomNode && ((StepAtomNode) input).getDescriptor() instanceof ErrorStep.DescriptorImpl; } }); assertNotNull(n); LogAction l = n.getAction(LogAction.class); assertNotNull(l); }
List<FlowNode> heads = execution.getCurrentHeads(); DepthFirstScanner scanner = new DepthFirstScanner(); FlowNode startFoo = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("foo")); assertNotNull(startFoo); assertTrue(startFoo instanceof BlockStartNode); FlowNode endFoo = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startFoo)); assertNotNull(endFoo); assertEquals(GenericStatus.FAILURE, StatusAndTiming.computeChunkStatus(b, null, startFoo, endFoo, null)); assertNotNull(endFoo.getError()); FlowNode startFirst = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("first")); assertNotNull(startFirst); assertTrue(startFirst instanceof BlockStartNode); FlowNode endFirst = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startFirst)); assertNotNull(endFirst); assertEquals(GenericStatus.FAILURE, StatusAndTiming.computeChunkStatus(b, null, startFirst, endFirst, null)); assertNotNull(endFirst.getError()); FlowNode startThird = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("third")); assertNotNull(startThird); assertTrue(startThird instanceof BlockStartNode); FlowNode endThird = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startThird)); assertNotNull(endThird); assertEquals(GenericStatus.NOT_EXECUTED, StatusAndTiming.computeChunkStatus(b, null, startThird, endThird, null));
@Override public void evaluate() throws Throwable { WorkflowJob p = rr.j.jenkins.getItemByFullName("p", WorkflowJob.class); assertNotNull(p); WorkflowRun b = p.getBuildByNumber(1); SemaphoreStep.success("wait/1", null); rr.j.assertBuildStatusSuccess(rr.j.waitForCompletion(b)); rr.j.assertLogContains("[Pipeline] { (" + SyntheticStageNames.postBuild() + ")", b); FlowExecution execution = b.getExecution(); assertNotNull(execution); Collection<FlowNode> heads = execution.getCurrentHeads(); DepthFirstScanner scanner = new DepthFirstScanner(); assertNotNull(scanner.findFirstMatch(heads, null, syntheticStagePredicate(SyntheticStageNames.postBuild(), SyntheticStage.getPost()))); SemaphoreStep.success("wait/2", null); rr.j.buildAndAssertSuccess(p); } });