org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode Java Examples

The following examples show how to use org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PipelineStepVisitor.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Override
public void chunkEnd(@Nonnull FlowNode endNode, @CheckForNull FlowNode afterChunk, @Nonnull ForkScanner scanner) {
    super.chunkEnd(endNode, afterChunk, scanner);
    if(endNode instanceof StepEndNode && PipelineNodeUtil.isStage(((StepEndNode)endNode).getStartNode())){
        currentStage = ((StepEndNode)endNode).getStartNode();
    } else {
        final String id = endNode.getEnclosingId();
        currentStage = endNode.getEnclosingBlocks().stream()
                .filter((block) -> block.getId().equals(id))
                .findFirst()
                .orElse(null);
    }
    if(node!= null && endNode instanceof StepEndNode && ((StepEndNode)endNode).getStartNode().equals(node)){
        this.stageStepsCollectionCompleted = false;
        this.inStageScope = true;
    }

    if (endNode instanceof StepStartNode && PipelineNodeUtil.isAgentStart(endNode)) {
        agentNode = (StepStartNode) endNode;
    }

    // if we're using marker-based (and not block-scoped) stages, add the last node as part of its contents
    if (!(endNode instanceof BlockEndNode)) {
        atomNode(null, endNode, afterChunk, scanner);
    }
}
 
Example #2
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testBuildStateForStageWithError() throws IOException {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    StepStartNode stageStartNode = mock(StepStartNode.class);
    ErrorAction error = mock(ErrorAction.class);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, mock(FlowNode.class));
    stageEndNode.addAction(error);

    GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener();
    BuildStage.State state = instance.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.CompletedError, state);
}
 
Example #3
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testBuildStateForStageWithTag() throws IOException {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    StepStartNode stageStartNode = mock (StepStartNode.class);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, mock(FlowNode.class));
    TagsAction tag = mock(TagsAction.class);
    stageEndNode.addAction(tag);
    when(tag.getTagValue(StageStatus.TAG_NAME)).thenReturn("SKIPPED_FOR_FAILURE");

    GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener();
    BuildStage.State state = instance.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.SkippedFailure, state);
}
 
Example #4
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void buildStateForStageSuccess() {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    when(execution.iotaStr()).thenReturn("1", "2", "3", "4");
    FlowStartNode parentNode = new FlowStartNode(execution, "5");
    StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode);

    BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.CompletedSuccess, result);
}
 
Example #5
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void buildStateForStageError() {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    when(execution.iotaStr()).thenReturn("1", "2", "3", "4");
    FlowStartNode parentNode = new FlowStartNode(execution, "5");
    StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode);

    ErrorAction errorAction = mock(ErrorAction.class);
    stageEndNode.addAction(errorAction);

    BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.CompletedError, result);
}
 
Example #6
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void buildStateForStageSkippedUnstable() {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    when(execution.iotaStr()).thenReturn("1", "2", "3", "4");
    FlowStartNode parentNode = new FlowStartNode(execution, "5");
    StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode);

    TagsAction tagsAction = mock(TagsAction.class);
    when(tagsAction.getTagValue(StageStatus.TAG_NAME)).thenReturn(StageStatus.getSkippedForUnstable());
    stageEndNode.addAction(tagsAction);

    BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.SkippedUnstable, result);
}
 
Example #7
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void buildStateForStageSkippedConditional() {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    when(execution.iotaStr()).thenReturn("1", "2", "3", "4");
    FlowStartNode parentNode = new FlowStartNode(execution, "5");
    StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode);

    TagsAction tagsAction = mock(TagsAction.class);
    when(tagsAction.getTagValue(StageStatus.TAG_NAME)).thenReturn(StageStatus.getSkippedForConditional());
    stageEndNode.addAction(tagsAction);

    BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.SkippedConditional, result);
}
 
Example #8
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void buildStateForStageFailedAndContinued() {
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    when(execution.iotaStr()).thenReturn("1", "2", "3", "4");
    FlowStartNode parentNode = new FlowStartNode(execution, "5");
    StepStartNode stageStartNode = new StepStartNode(execution, null, parentNode);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, parentNode);

    TagsAction tagsAction = mock(TagsAction.class);
    when(tagsAction.getTagValue(StageStatus.TAG_NAME)).thenReturn(StageStatus.getFailedAndContinued());
    stageEndNode.addAction(tagsAction);

    BuildStage.State result = GithubBuildStatusGraphListener.buildStateForStage(stageStartNode, stageEndNode);
    assertEquals(BuildStage.State.CompletedError, result);
}
 
Example #9
Source File: PipelineStepImpl.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
public String getStepType() {
    FlowNode flowNode = this.node.getNode();
    if (flowNode instanceof StepNode && !(flowNode instanceof StepEndNode)) {
        StepNode stepNode = (StepNode) flowNode;
        StepDescriptor descriptor = stepNode.getDescriptor();
        if (descriptor != null) return descriptor.getId();
    }
    return "unknown";
}
 
Example #10
Source File: PipelineNodeGraphVisitor.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
public void parallelEnd(@Nonnull FlowNode parallelStartNode, @Nonnull FlowNode parallelEndNode, @Nonnull ForkScanner scanner) {
    if (isNodeVisitorDumpEnabled) {
        dump(String.format("parallelEnd=> id: %s, name: %s, function: %s", parallelEndNode.getId(),
                           parallelEndNode.getDisplayName(), parallelEndNode.getDisplayFunctionName()));
        if (parallelEndNode instanceof StepEndNode) {
            dump(String.format("parallelEnd=> id: %s, StartNode: %s, name: %s, function: %s", parallelEndNode.getId(),
                               ((StepEndNode) parallelEndNode).getStartNode().getId(), ((StepEndNode) parallelEndNode).getStartNode().getDisplayName(), ((StepEndNode) parallelEndNode).getStartNode().getDisplayFunctionName()));
        }
    }
    captureOrphanParallelBranches();
    this.parallelEnds.add(parallelEndNode);
}
 
Example #11
Source File: PipelineNodeGraphVisitor.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
public void parallelBranchEnd(@Nonnull FlowNode parallelStartNode, @Nonnull FlowNode branchEndNode, @Nonnull ForkScanner scanner) {
    if (isNodeVisitorDumpEnabled) {
        dump(String.format("parallelBranchEnd=> id: %s, name: %s, function: %s, type: %s", branchEndNode.getId(),
                           branchEndNode.getDisplayName(), branchEndNode.getDisplayFunctionName(), branchEndNode.getClass()));
        if (branchEndNode instanceof StepEndNode) {
            dump(String.format("parallelBranchEnd=> id: %s, StartNode: %s, name: %s, function: %s", branchEndNode.getId(),
                               ((StepEndNode) branchEndNode).getStartNode().getId(), ((StepEndNode) branchEndNode).getStartNode().getDisplayName(),
                               ((StepEndNode) branchEndNode).getStartNode().getDisplayFunctionName()));
        }
    }
    pendingBranchEndNodes.add(branchEndNode);
    parallelBranchStartNodes.add(parallelStartNode);
}
 
Example #12
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 4 votes vote down vote up
@Test
public void testStepEndNode() throws Exception {
    long time = 12345L;

    // Mocked objects
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    StepStartNode stageStartNode = mock(StepStartNode.class);
    StepEndNode stageEndNode = new StepEndNode(execution, stageStartNode, mock(FlowNode.class));

    ErrorAction error = mock(ErrorAction.class);
    stageEndNode.addAction(error);

    TimingAction startTime = mock(TimingAction.class);
    TimingAction endTime = mock(TimingAction.class);
    stageEndNode.addAction(endTime);
    when(startTime.getStartTime()).thenReturn(0L);
    when(endTime.getStartTime()).thenReturn(time);

    BuildStatusAction buildStatus = mock(BuildStatusAction.class);
    FlowExecutionOwner owner = mock(FlowExecutionOwner.class);
    AbstractBuild build = mock(AbstractBuild.class);

    // get BuildStatusAction from StepEndNode
    when(execution.getOwner()).thenReturn(owner);
    when(owner.getExecutable()).thenReturn(build);
    when(build.getAction(BuildStatusAction.class)).thenReturn(buildStatus);

    // get StepStartNode from StepEndNode
    String startId = "15";
    when(stageStartNode.getId()).thenReturn(startId);
    when(execution.getNode(startId)).thenReturn(stageStartNode);

    // get time from StepStartNode to StepEndNode
    when(stageStartNode.getAction(TimingAction.class)).thenReturn(startTime);
    LabelAction labelAction = new LabelAction("some label");
    when(stageStartNode.getAction(LabelAction.class)).thenReturn(labelAction);
    when(stageStartNode.getAction(StageAction.class)).thenReturn(mock(StageAction.class));

    GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener();
    instance.onNewHead(stageEndNode);
    verify(buildStatus).updateBuildStatusForStage(eq("some label"), eq(BuildStage.State.CompletedError), eq(time));
}
 
Example #13
Source File: GitLabSCMPublishAction.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 4 votes vote down vote up
private boolean isStageEndNode(FlowNode node, String startNodeId) {
    return startNodeId != null && node instanceof StepEndNode && ((StepEndNode) node).getStartNode().getId().equals(startNodeId);
}
 
Example #14
Source File: PipelineStepVisitor.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
public void parallelBranchEnd(@Nonnull FlowNode parallelStartNode, @Nonnull FlowNode branchEndNode, @Nonnull ForkScanner scanner) {
    if(!stageStepsCollectionCompleted && node != null && PipelineNodeUtil.isParallelBranch(node) && branchEndNode instanceof StepEndNode){
        resetSteps();
    }
}
 
Example #15
Source File: PipelineNodeGraphVisitor.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
public void chunkEnd(@Nonnull FlowNode endNode, @CheckForNull FlowNode afterBlock, @Nonnull ForkScanner scanner) {
    super.chunkEnd(endNode, afterBlock, scanner);

    if (isNodeVisitorDumpEnabled) {
        dump(String.format("chunkEnd=> id: %s, name: %s, function: %s, type:%s", endNode.getId(),
                           endNode.getDisplayName(), endNode.getDisplayFunctionName(), endNode.getClass()));
    }

    if (isNodeVisitorDumpEnabled && endNode instanceof StepEndNode) {
        dump("\tStartNode: " + ((StepEndNode) endNode).getStartNode());
    }

    if (endNode instanceof StepStartNode && PipelineNodeUtil.isAgentStart(endNode)) {
        agentNode = (StepStartNode) endNode;
    }

    // capture orphan branches
    captureOrphanParallelBranches();

    //if block stage node push it to stack as it may have nested stages
    if (parallelEnds.isEmpty() &&
        endNode instanceof StepEndNode
        && !PipelineNodeUtil.isSyntheticStage(((StepEndNode) endNode).getStartNode()) //skip synthetic stages
        && PipelineNodeUtil.isStage(((StepEndNode) endNode).getStartNode())) {

        //XXX: There seems to be bug in eventing, chunkEnd is sent twice for the same FlowNode
        //     Lets peek and if the last one is same as this endNode then skip adding it
        FlowNode node = null;
        if (!nestedStages.empty()) {
            node = nestedStages.peek();
        }
        if (node == null || !node.equals(endNode)) {
            nestedStages.push(endNode);
        }

    }
    firstExecuted = null;

    // if we're using marker-based (and not block-scoped) stages, add the last node as part of its contents
    if (!(endNode instanceof BlockEndNode)) {
        atomNode(null, endNode, afterBlock, scanner);
    }
}