Java Code Examples for org.jenkinsci.plugins.workflow.job.WorkflowRun#isBuilding()
The following examples show how to use
org.jenkinsci.plugins.workflow.job.WorkflowRun#isBuilding() .
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: BuildCulpritsWorkflowRun.java From jenkins-build-monitor-plugin with MIT License | 6 votes |
@Override public Set<String> getCulprits(Run<?, ?> run) { WorkflowRun workflowRun = (WorkflowRun) run; Set<String> culprits = new TreeSet<String>(); //Workaround while waiting for https://issues.jenkins-ci.org/browse/JENKINS-24141 WorkflowRun previous = workflowRun.getPreviousCompletedBuild(); if (workflowRun.isBuilding()) { //We are currently building so add culprits from previous build (if any) if (previous != null) { Result previousResult = previous.getResult(); if (previousResult != null && previousResult.isWorseThan(Result.SUCCESS)) { culprits.addAll(getCommitters(previous)); } } } culprits.addAll(getCommitters(workflowRun)); //Get culprits from earlier builds if (previous != null && previous.getPreviousNotFailedBuild() != null) { culprits.addAll(getCulpritsForRun(previous.getPreviousNotFailedBuild(), previous)); } return culprits; }
Example 2
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 4 votes |
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); return completeNodeNames; // So caller can do any additional checks }
Example 3
Source File: PipelineNodeTest.java From blueocean-plugin with MIT License | 4 votes |
@Ignore("Fails on ci.jenkins.io but not locally. Reasons unclear. Likely a timing issue.") @Test public void sequentialParallelStagesLongRun() throws Exception { WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "sequential_parallel_stages_long_run_time.jenkinsfile"); Slave s = j.createOnlineSlave(); s.setNumExecutors(3); WorkflowRun run = p.scheduleBuild2(0).waitForStart(); j.waitForCompletion(run); List<String> watchedStages = Arrays.asList("first-sequential-stage", "second-sequential-stage", "third-sequential-stage"); run = p.scheduleBuild2(0).waitForStart(); Thread.sleep(1000); long loopCount = 0; while (run.isBuilding()) { PipelineNodeContainerImpl pipelineNodeContainer = new PipelineNodeContainerImpl(run, new Link("foo")); List<BluePipelineNode> nodes = pipelineNodeContainer.getNodes(); for (BluePipelineNode node : nodes) { if (StringUtils.isEmpty(node.getFirstParent()) && watchedStages.contains(node.getDisplayName())) { LOGGER.error("node {} has getFirstParent null", node); fail("node with getFirstParent null:" + node); } // we try to find edges with id for a non existing node in the list List<BluePipelineNode.Edge> emptyEdges = node.getEdges().stream().filter(edge -> !nodes.stream() .filter(bluePipelineNode -> bluePipelineNode.getId().equals(edge.getId())) .findFirst().isPresent() ).collect(Collectors.toList()); if (!emptyEdges.isEmpty()) { // TODO remove this weird if but it's only to have breakpoint in IDE assertTrue("edges with unknown nodes" + nodes, !emptyEdges.isEmpty()); } } LOGGER.debug("nodes size {}", nodes.size()); if (nodes.size() != 9) { LOGGER.info("loop: " + loopCount + ", nodes size {}", nodes.size()); LOGGER.info("nodes != 9 {}", nodes); fail("nodes != 9: " + nodes); } Thread.sleep(100); } }