use of io.jenkins.blueocean.rest.model.BluePipelineStep in project blueocean-plugin by jenkinsci.
the class PipelineNodeGraphVisitor method getPipelineNodeSteps.
@Override
public List<BluePipelineStep> getPipelineNodeSteps(final String nodeId, Link parent) {
FlowExecution execution = run.getExecution();
if (execution == null) {
logger.debug(String.format("Pipeline %s, runid %s has null execution", run.getParent().getName(), run.getId()));
return Collections.emptyList();
}
DepthFirstScanner depthFirstScanner = new DepthFirstScanner();
// If blocked scope, get the end node
FlowNode n = depthFirstScanner.findFirstMatch(execution.getCurrentHeads(), input -> (input != null && input.getId().equals(nodeId) && (PipelineNodeUtil.isStage(input) || PipelineNodeUtil.isParallelBranch(input))));
if (n == null) {
// if no node found or the node is not stage or parallel we return empty steps
return Collections.emptyList();
}
PipelineStepVisitor visitor = new PipelineStepVisitor(run, n);
ForkScanner.visitSimpleChunks(execution.getCurrentHeads(), visitor, new StageChunkFinder());
return visitor.getSteps().stream().map(node -> new PipelineStepImpl(node, parent)).collect(Collectors.toList());
}
use of io.jenkins.blueocean.rest.model.BluePipelineStep in project blueocean-plugin by jenkinsci.
the class NodeLogResource method doIndex.
public void doIndex(StaplerRequest req, StaplerResponse rsp, @Header("Accept") AcceptHeader accept) {
String download = req.getParameter("download");
if ("true".equalsIgnoreCase(download)) {
rsp.setHeader("Content-Disposition", "attachment; filename=log.txt");
}
rsp.setContentType("text/plain;charset=UTF-8");
rsp.setStatus(HttpServletResponse.SC_OK);
long count = 0;
try (CharSpool spool = new CharSpool()) {
for (BluePipelineStep blueStep : steps) {
if (blueStep instanceof PipelineStepImpl) {
PipelineStepImpl step = (PipelineStepImpl) blueStep;
final FlowNodeWrapper node = step.getFlowNodeWrapper();
if (node.isLoggable()) {
LogAction logAction = node.getNode().getAction(LogAction.class);
if (logAction != null) {
count += logAction.getLogText().writeLogTo(0, spool);
String errorLog = node.blockError();
if (errorLog != null) {
count += appendError(errorLog, new WriterOutputStream(spool));
}
}
} else {
String errorLog = step.getFlowNodeWrapper().nodeError();
if (errorLog == null) {
errorLog = step.getFlowNodeWrapper().blockError();
}
if (errorLog != null) {
count += appendError(errorLog, new WriterOutputStream(spool));
}
}
}
}
Writer writer;
if (count > 0) {
writer = (count > 4096) ? rsp.getCompressedWriter(req) : rsp.getWriter();
spool.flush();
spool.writeTo(new LineEndNormalizingWriter(writer));
rsp.addHeader("X-Text-Size", String.valueOf(count));
writer.close();
}
} catch (IOException e) {
throw new ServiceException.UnexpectedErrorException("Error reading log");
}
}
use of io.jenkins.blueocean.rest.model.BluePipelineStep in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method checkConsistencyWhileBuilding.
private String checkConsistencyWhileBuilding(String jenkinsFileName) throws Exception {
/*
Run a complex pipeline to completion, then start a new build and inspect it while it's running, to exercise
the code that merges incomplete runs with previous builds to generate a complete graph
*/
WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), jenkinsFileName);
// Do an initial run, collect the nodes
final WorkflowRun run1 = p.scheduleBuild2(0).waitForStart();
j.waitForCompletion(run1);
final List<BluePipelineNode> completeNodes = new PipelineNodeContainerImpl(run1, new Link("foo")).getNodes();
final String completeNodeNames = completeNodes.stream().map(BluePipelineStep::getDisplayName).sorted().collect(Collectors.joining(", "));
// Start another build...
final WorkflowRun run2 = p.scheduleBuild2(0).waitForStart();
// ... then watch while it runs, checking for the same graph nodes
int loopCount = 0;
do {
Thread.sleep(1000);
List<BluePipelineNode> runningNodes = new PipelineNodeContainerImpl(run2, new Link("foo")).getNodes();
String runningNodeNames = runningNodes.stream().map(BluePipelineStep::getDisplayName).sorted().collect(Collectors.joining(", "));
assertEquals("running node names", completeNodeNames, runningNodeNames);
loopCount++;
} while (run2.isBuilding());
// Sanity check, make sure we're *actually* checking stuff.
assertTrue("Checked multiple times while building", loopCount > 5);
// So caller can do any additional checks
return completeNodeNames;
}
use of io.jenkins.blueocean.rest.model.BluePipelineStep in project blueocean-plugin by jenkinsci.
the class PipelineNodeGraphVisitor method getPipelineNodeSteps.
@Override
public List<BluePipelineStep> getPipelineNodeSteps(Link parent) {
FlowExecution execution = run.getExecution();
if (execution == null) {
return Collections.emptyList();
}
PipelineStepVisitor visitor = new PipelineStepVisitor(run, null);
ForkScanner.visitSimpleChunks(execution.getCurrentHeads(), visitor, new StageChunkFinder());
return visitor.getSteps().stream().map(node -> new PipelineStepImpl(node, parent)).collect(Collectors.toList());
}
use of io.jenkins.blueocean.rest.model.BluePipelineStep in project blueocean-plugin by jenkinsci.
the class LinkResolverImpl method resolve.
@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;
}
Aggregations