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

The following examples show how to use org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode. 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: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 6 votes vote down vote up
@Test
public void testStageNode() throws IOException {
    StepStartNode stageNode = mock(StepStartNode.class);
    StageAction stageAction = mock(StageAction.class);
    FlowExecution execution = mock(FlowExecution.class);
    when(stageNode.getAction(StageAction.class)).thenReturn(stageAction);
    when(stageNode.getExecution()).thenReturn(execution);
    FlowExecutionOwner owner = mock(FlowExecutionOwner.class);
    when(execution.getOwner()).thenReturn(owner);
    AbstractBuild build = mock(AbstractBuild.class);

    when(owner.getExecutable()).thenReturn(build);
    ExecutionModelAction executionModel = mock(ExecutionModelAction.class);
    when(build.getAction(ExecutionModelAction.class)).thenReturn(executionModel);

    ModelASTStages stages = new ModelASTStages(null);
    when(executionModel.getStages()).thenReturn(stages);

    GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener();
    instance.onNewHead(stageNode);
    verify(build).addAction(any(BuildStatusAction.class));
}
 
Example #2
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 #3
Source File: PipelineNodeUtil.java    From blueocean-plugin with MIT License 6 votes vote down vote up
/**
 * Determine if the given {@link FlowNode} is the initial {@link StepStartNode} for an {@link org.jenkinsci.plugins.workflow.support.steps.ExecutorStep}.
 *
 * @param node a possibly null {@link FlowNode}
 * @return true if {@code node} is the non-body start of the agent execution.
 */
public static boolean isAgentStart(@Nullable FlowNode node) {
    if (node != null) {
        if (node instanceof StepStartNode) {
            StepStartNode stepStartNode = (StepStartNode) node;
            if (stepStartNode.getDescriptor() != null) {
                StepDescriptor sd = stepStartNode.getDescriptor();
                return sd != null &&
                    ExecutorStep.DescriptorImpl.class.equals(sd.getClass()) &&
                    !stepStartNode.isBody();
            }
        }
    }

    return false;
}
 
Example #4
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
public void testComplexPipeline() throws IOException {
    StepStartNode stageNode = mock(StepStartNode.class);
    StageAction stageAction = mock(StageAction.class);
    FlowExecution execution = mock(FlowExecution.class);
    when(stageNode.getAction(StageAction.class)).thenReturn(stageAction);
    when(stageNode.getExecution()).thenReturn(execution);
    FlowExecutionOwner owner = mock(FlowExecutionOwner.class);
    when(execution.getOwner()).thenReturn(owner);
    AbstractBuild build = mock(AbstractBuild.class);

    when(owner.getExecutable()).thenReturn(build);
    ExecutionModelAction executionModel = mock(ExecutionModelAction.class);
    when(build.getAction(ExecutionModelAction.class)).thenReturn(executionModel);

    // Construct a complex pipeline model
    ModelASTStages stages = createStages("Outer Stage 1", "Outer Stage 2");
    ModelASTStages innerStages = createStages("Inner Stage 1", "Inner Stage 2", "Inner Stage 3");
    ModelASTStages innerInnerStages = createStages("Inner Inner Stage 1");
    ModelASTStages parallelStages = createStages("Parallel Stage 1", "Parallel Stage 2");
    stages.getStages().get(0).setStages(innerStages);
    innerStages.getStages().get(2).setStages(innerInnerStages);
    stages.getStages().get(1).setParallelContent(parallelStages.getStages());
    // Create a linear list of the pipeline stages for comparison
    List<String> fullStageList = Arrays.asList(new String[]{"Outer Stage 1", "Inner Stage 1", "Inner Stage 2", "Inner Stage 3", "Inner Inner Stage 1", "Outer Stage 2", "Parallel Stage 1", "Parallel Stage 2"});

    when(executionModel.getStages()).thenReturn(stages);

    GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener();
    instance.onNewHead(stageNode);
    verify(build).addAction(any(BuildStatusAction.class));
    // Check that the pipeline stages found match the list of expected stages
    assertTrue(GithubBuildStatusGraphListener.getDeclarativeStages(build).equals(fullStageList));
}
 
Example #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 5 votes vote down vote up
private static Predicate<FlowNode> stageForName(final String name) {
    return new Predicate<FlowNode>() {
        @Override
        public boolean apply(@Nullable FlowNode input) {
            return input instanceof StepStartNode &&
                    ((StepStartNode) input).getDescriptor() instanceof StageStep.DescriptorImpl &&
                    input.getDisplayName().equals(name);
        }
    };
}
 
Example #13
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 #14
Source File: GitLabSCMPublishAction.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 4 votes vote down vote up
private boolean isNamedStageStartNode(FlowNode node) {
    return node instanceof StepStartNode && Objects.equals(((StepStartNode) node).getStepName(), "Stage") && !Objects.equals(node.getDisplayFunctionName(), "stage");
}
 
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);
    }
}
 
Example #16
Source File: WorkflowNodeTraversal.java    From jenkins-build-monitor-plugin with MIT License 4 votes vote down vote up
@Override
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Descriptor should never be null")
protected boolean isStageStep(FlowNode node) {
    return node instanceof StepStartNode
            && ((StepStartNode) node).getDescriptor().isSubTypeOf(StageStep.class);
}