@Override public StepExecution start(StepContext context) throws Exception { return new JUnitResultsStepExecution(this, context); }
List<FlowNode> enclosingBlocks = JUnitResultsStepExecution.getEnclosingStagesAndParallels(node); PipelineTestDetails pipelineTestDetails = new PipelineTestDetails(); pipelineTestDetails.setNodeId(nodeId); pipelineTestDetails.setEnclosingBlocks(JUnitResultsStepExecution.getEnclosingBlockIds(enclosingBlocks)); pipelineTestDetails.setEnclosingBlockNames(JUnitResultsStepExecution.getEnclosingBlockNames(enclosingBlocks));
@Override protected TestResultSummary run() throws Exception { FilePath workspace = getContext().get(FilePath.class); workspace.mkdirs(); Run<?,?> run = getContext().get(Run.class); TaskListener listener = getContext().get(TaskListener.class); Launcher launcher = getContext().get(Launcher.class); FlowNode node = getContext().get(FlowNode.class); String nodeId = node.getId(); List<FlowNode> enclosingBlocks = getEnclosingStagesAndParallels(node); PipelineTestDetails pipelineTestDetails = new PipelineTestDetails(); pipelineTestDetails.setNodeId(nodeId); pipelineTestDetails.setEnclosingBlocks(getEnclosingBlockIds(enclosingBlocks)); pipelineTestDetails.setEnclosingBlockNames(getEnclosingBlockNames(enclosingBlocks)); try { TestResultAction testResultAction = JUnitResultArchiver.parseAndAttach(step, pipelineTestDetails, run, workspace, launcher, listener); if (testResultAction != null) { // TODO: Once JENKINS-43995 lands, update this to set the step status instead of the entire build. if (testResultAction.getResult().getFailCount() > 0) { run.setResult(Result.UNSTABLE); } return new TestResultSummary(testResultAction.getResult().getResultByNode(nodeId)); } } catch (Exception e) { listener.getLogger().println(e.getMessage()); throw e; } return new TestResultSummary(); }
/** * Get the stage and parallel branch start node IDs (not the body nodes) for this node, innermost first. * @param node A flownode. * @return A nonnull, possibly empty list of stage/parallel branch start nodes, innermost first. */ @Nonnull public static List<FlowNode> getEnclosingStagesAndParallels(FlowNode node) { List<FlowNode> enclosingBlocks = new ArrayList<>(); for (FlowNode enclosing : node.getEnclosingBlocks()) { if (enclosing != null && enclosing.getAction(LabelAction.class) != null) { if (isStageNode(enclosing) || (enclosing.getAction(ThreadNameAction.class) != null)) { enclosingBlocks.add(enclosing); } } } return enclosingBlocks; }
step.getThresholdMode(), new ExtraConfiguration(step.getTestTimeMarginAsLong(), step.isReduceLog())); List<FlowNode> enclosingBlocks = JUnitResultsStepExecution.getEnclosingStagesAndParallels(node); pipelineTestDetails.setEnclosingBlocks(JUnitResultsStepExecution.getEnclosingBlockIds(enclosingBlocks)); pipelineTestDetails.setEnclosingBlockNames(JUnitResultsStepExecution.getEnclosingBlockNames(enclosingBlocks)); xUnitProcessor.process(run, workspace, listener, launcher, step.getTestDataPublishers(), pipelineTestDetails);