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

The following examples show how to use org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode. 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 testAtomNode() throws IOException {
    ErrorAction error = mock(ErrorAction.class);
    CpsFlowExecution execution = mock(CpsFlowExecution.class);

    StepAtomNode stageNode = new StepAtomNode(execution, null, mock(FlowNode.class));
    stageNode.addAction(error);

    FlowExecutionOwner owner = mock(FlowExecutionOwner.class);
    when(execution.getOwner()).thenReturn(owner);

    Executable exec = mock(Executable.class);
    when(owner.getExecutable()).thenReturn(exec);

    AbstractBuild build = mock(AbstractBuild.class);
    when(owner.getExecutable()).thenReturn(build);
    when(build.getAction(ExecutionModelAction.class)).thenReturn(null); // not declarative

    BuildStatusAction buildStatusAction = mock(BuildStatusAction.class);
    when(build.getAction(BuildStatusAction.class)).thenReturn(buildStatusAction);

    GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener();
    instance.onNewHead(stageNode);
    verify(buildStatusAction).sendNonStageError(any());
}
 
Example #2
Source File: GithubBuildStatusGraphListenerTest.java    From github-autostatus-plugin with MIT License 6 votes vote down vote up
/**
 * Verifies onNewHead adds the build action for an atom node if there's an error (used for sending errors that occur
 * out of a stage
 */
@Test
public void testAtomNodeAddsAction() throws IOException {
    ErrorAction error = mock(ErrorAction.class);
    CpsFlowExecution execution = mock(CpsFlowExecution.class);
    StepAtomNode stageNode = new StepAtomNode(execution, null, mock(FlowNode.class));
    stageNode.addAction(error);

    FlowExecutionOwner owner = mock(FlowExecutionOwner.class);
    when(execution.getOwner()).thenReturn(owner);
    AbstractBuild build = mock(AbstractBuild.class);
    when(owner.getExecutable()).thenReturn(build);
    when(build.getAction(ExecutionModelAction.class)).thenReturn(null); // not declarative

    GithubBuildStatusGraphListener instance = new GithubBuildStatusGraphListener();
    instance.onNewHead(stageNode);
    verify(build).addAction(any(BuildStatusAction.class));
}
 
Example #3
Source File: LinkResolverImpl.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Override
public Link resolve(Object modelObject) {
    if (modelObject instanceof FlowNode) {
        FlowNode flowNode = (FlowNode) modelObject;
        BlueRun r = resolveFlowNodeRun(flowNode);
        if (PipelineNodeUtil.isParallelBranch(flowNode) || PipelineNodeUtil.isStage(flowNode)) { // its Node
            if (r != null) {
                return r.getLink().rel("nodes/" + flowNode.getId());
            }
        } else if (flowNode instanceof StepAtomNode && !PipelineNodeUtil.isStage(flowNode)) {
            if (r != null) {
                return r.getLink().rel("steps/" + flowNode.getId());
            }
        }
    }else if(modelObject instanceof BluePipelineNode || modelObject instanceof BluePipelineStep){
        return ((Resource) modelObject).getLink();
    }
    return null;
}
 
Example #4
Source File: GithubBuildStatusGraphListener.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
/**
 * Determines if a {@link FlowNode} describes a stage.
 *
 * Note: this check is copied from PipelineNodeUtil.java in blueocean-plugin
 *
 * @param node node of a workflow
 * @return true if it's a stage node; false otherwise
 */
private static boolean isStage(FlowNode node) {
    if (node instanceof StepAtomNode) {
        // This filters out labelled steps, such as `sh(script: "echo 'hello'", label: 'echo')`
        return false;
    }
    return node != null && ((node.getAction(StageAction.class) != null)
            || (node.getAction(LabelAction.class) != null && node.getAction(ThreadNameAction.class) == null));
}
 
Example #5
Source File: PipelineNodeUtil.java    From blueocean-plugin with MIT License 5 votes vote down vote up
public static boolean isPausedForInputStep(@Nonnull StepAtomNode step, @Nullable InputAction inputAction){
    if(inputAction == null){
        return false;
    }
    PauseAction pauseAction = step.getAction(PauseAction.class);
    return (pauseAction != null && pauseAction.isPaused()
            && pauseAction.getCause().equals("Input"));
}
 
Example #6
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 5 votes vote down vote up
@Issue("JENKINS-48250")
@Test
public void emptyFails() throws Exception {
    WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "emptyFails");
    j.setDefinition(new CpsFlowDefinition("stage('first') {\n" +
            "  node {\n" +
            (Functions.isWindows() ?
            "    bat 'echo hi'\n" :
            "    sh 'echo hi'\n") +
            "    junit('*.xml')\n" +
            "  }\n" +
            "}\n", true));

    WorkflowRun r = j.scheduleBuild2(0).waitForStart();
    rule.assertBuildStatus(Result.FAILURE, rule.waitForCompletion(r));
    rule.assertLogContains("ERROR: " + Messages.JUnitResultArchiver_NoTestReportFound(), r);
    FlowExecution execution = r.getExecution();
    DepthFirstScanner scanner = new DepthFirstScanner();
    FlowNode f = scanner.findFirstMatch(execution, new Predicate<FlowNode>() {
        @Override
        public boolean apply(@Nullable FlowNode input) {
            return input instanceof StepAtomNode &&
                    ((StepAtomNode) input).getDescriptor() instanceof JUnitResultsStep.DescriptorImpl;
        }
    });
    assertNotNull(f);
    LogAction logAction = f.getPersistentAction(LogAction.class);
    assertNotNull(logAction);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    logAction.getLogText().writeRawLogTo(0, baos);
    String log = baos.toString();
    assertThat(log, CoreMatchers.containsString(Messages.JUnitResultArchiver_NoTestReportFound()));
}
 
Example #7
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 5 votes vote down vote up
private static List<FlowNode> findJUnitSteps(BlockStartNode blockStart) {
    return new DepthFirstScanner().filteredNodes(
            Collections.singletonList(blockStart.getEndNode()),
            Collections.singletonList(blockStart),
            node -> node instanceof StepAtomNode &&
                    ((StepAtomNode) node).getDescriptor() instanceof JUnitResultsStep.DescriptorImpl
    );
}