@CheckForNull protected Result getExecutionResult(@Nonnull WorkflowRun r) { FlowExecution execution = r.getExecution(); if (execution instanceof CpsFlowExecution) { return ((CpsFlowExecution) execution).getResult(); } else { return r.getResult(); } }
public FlowGraphTable getFlowGraph() { FlowGraphTable t = new FlowGraphTable(run.getExecution()); t.build(); return t; }
@Override public void run() { build.addAction(new RunningContextsAction()); FlowExecution execution = build.getExecution(); if (execution != null) { execution.addListener(listener); } else { LOGGER.log(SEVERE, "could not get flow-execution for build " + build.getFullDisplayName()); } } },
@Override public void evaluate() throws Throwable { WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, "durableAgainstClean", FlowDurabilityHint.PERFORMANCE_OPTIMIZED); Assert.assertEquals(FlowDurabilityHint.PERFORMANCE_OPTIMIZED, run.getExecution().getDurabilityHint()); logStart[0] = JenkinsRule.getLog(run); CpsFlowExecution exec = (CpsFlowExecution)(run.getExecution()); // Ensure the storage file is unreadable try (FileChannel fis = new FileOutputStream(new File(exec.getStorageDir(), "flowNodeStore.xml")).getChannel()) { fis.truncate(5); // Leave a tiny bit just to make things more interesting } } });
@Override public void evaluate() throws Throwable { WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild(); assert run.isBuilding(); assert run.getResult() != Result.FAILURE; Thread.sleep(35000); // Step completes if (run.getExecution() instanceof CpsFlowExecution) { CpsFlowExecution exec = (CpsFlowExecution)run.getExecution(); assert exec.persistedClean == null; } } });
static boolean blocksRestart(WorkflowRun b) throws Exception { if (b.getExecutor().getAsynchronousExecution().blocksRestart()) { return true; } // TODO delete when implemented in workflow-cps: return b.getExecution().getCurrentExecutions(false).get(1, TimeUnit.SECONDS).stream().anyMatch(StepExecution::blocksRestart); }
private static void verifyExecutionRemoved(WorkflowRun run) throws Exception{ // Verify we've removed all FlowExcecutionList entries FlowExecutionList list = FlowExecutionList.get(); for (FlowExecution fe : list) { if (fe == run.getExecution()) { Assert.fail("Run still has an execution in the list and should be removed!"); } } Field f = list.getClass().getDeclaredField("runningTasks"); f.setAccessible(true); CopyOnWriteList<FlowExecutionOwner> runningTasks = (CopyOnWriteList<FlowExecutionOwner>)(f.get(list)); Assert.assertFalse(runningTasks.contains(run.asFlowExecutionOwner())); }
@Override public void evaluate() throws Throwable { Jenkins jenkins = story.j.jenkins; WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.PERFORMANCE_OPTIMIZED); FlowExecution exec = run.getExecution(); assertBaseStorageType(exec, BulkFlowNodeStorage.class); logStart[0] = JenkinsRule.getLog(run); } });
@Override public void evaluate() throws Throwable { WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild(); Assert.assertEquals(FlowDurabilityHint.PERFORMANCE_OPTIMIZED, run.getExecution().getDurabilityHint()); assertBaseStorageType(run.getExecution(), BulkFlowNodeStorage.class); verifySafelyResumed(story.j, run, true, logStart[0]); } });
/** * Updates p, b, and e variables from the given JenkinsRule */ public void rebuildContext(JenkinsRule j) throws Exception { WorkflowJob p2 = (WorkflowJob) j.jenkins.getItem("demo"); assertNotNull("could not find a job named demo", p2); assert p!=p2; // make sure Jenkins was restarted p = p2; WorkflowRun b2 = p.getLastBuild(); assert b!=b2; b = b2; e = (CpsFlowExecution) b.getExecution(); }
/** Execution bombed out due to some sort of irrecoverable persistence issue. */ static void assertNulledExecution(WorkflowRun run) throws Exception { if (run.isBuilding()) { System.out.println("Run initially building, going to wait a second to see if it finishes, run="+run); Thread.sleep(1000); } Assert.assertFalse(run.isBuilding()); Assert.assertNotNull(run.getResult()); FlowExecution fe = run.getExecution(); Assert.assertNull(fe); }
@Test public void inProgressButFlowNodesLost() throws Exception { final int[] build = new int[1]; story.thenWithHardShutdown( j -> { WorkflowRun run = runBasicPauseOnInput(j, DEFAULT_JOBNAME, build); CpsFlowExecution cpsExec = (CpsFlowExecution)(run.getExecution()); FileUtils.deleteDirectory(((CpsFlowExecution)(run.getExecution())).getStorageDir()); }); story.then( j->{ WorkflowJob r = j.jenkins.getItemByFullName(DEFAULT_JOBNAME, WorkflowJob.class); WorkflowRun run = r.getBuildByNumber(build[0]); assertCompletedCleanly(run); }); }
@Override public void evaluate() throws Throwable { WorkflowJob p = story.j.jenkins.getItemByFullName("p", WorkflowJob.class); WorkflowRun b = p.getLastBuild(); SemaphoreStep.success("wait/1", null); story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)); assertThat(logger.getRecords(), Matchers.hasSize(Matchers.equalTo(1))); assertEquals(CpsFlowExecution.TimingKind.values().length, ((CpsFlowExecution) b.getExecution()).timings.keySet().size()); } });
@Override public void evaluate() throws Throwable { WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, "durableAgainstClean", FlowDurabilityHint.PERFORMANCE_OPTIMIZED); Assert.assertEquals(FlowDurabilityHint.PERFORMANCE_OPTIMIZED, run.getExecution().getDurabilityHint()); logStart[0] = JenkinsRule.getLog(run); } });
@Override public void evaluate() throws Throwable { Jenkins jenkins = story.j.jenkins; WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY); FlowExecution exec = run.getExecution(); if (exec instanceof CpsFlowExecution) { assert ((CpsFlowExecution) exec).getStorage().isPersistedFully(); } logStart[0] = JenkinsRule.getLog(run); } });
@Override public void evaluate() throws Throwable { Jenkins jenkins = story.j.jenkins; WorkflowRun run = createAndRunBasicJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY); FlowExecution exec = run.getExecution(); if (exec instanceof CpsFlowExecution) { assert ((CpsFlowExecution) exec).getStorage().isPersistedFully(); } logStart[0] = JenkinsRule.getLog(run); } });
@Test public void simpleSemaphoreStep() throws Exception { WorkflowJob job = r.jenkins.createProject(WorkflowJob.class, "p"); job.setDefinition(new CpsFlowDefinition("semaphore 'wait'", false)); WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get(); SemaphoreStep.waitForStart("wait/1", run); FlowNode semaphoreNode = run.getExecution().getCurrentHeads().get(0); CpsThread thread = CpsThread.current(); SemaphoreStep.success("wait/1", null); r.waitForCompletion(run); testDeserialize(run.getExecution()); }
public static Pipeline resolve(WorkflowJob project, WorkflowRun build) throws PipelineException { String pipelineTimestamp = TimestampFormat.formatTimestamp(build.getTimeInMillis()); List<FlowNode> stageNodes = FlowNodeUtil.getStageNodes(build.getExecution()); return new Pipeline(project.getName(), build.getDisplayName(), Stage.extractStages(build, stageNodes), Change.getChanges(build.getChangeSets()), TriggerCause.getTriggeredBy(project, build), pipelineTimestamp); }
public static void assertStageResults(WorkflowRun run, int suiteCount, int testCount, int failCount, String stageName) { FlowExecution execution = run.getExecution(); DepthFirstScanner scanner = new DepthFirstScanner(); FlowNode aStage = scanner.findFirstMatch(execution, stageForName(stageName)); assertNotNull(aStage); assertBlockResults(run, suiteCount, testCount, failCount, aStage); }
@Override public void evaluate() throws Throwable { WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("semaphore 'wait'; echo 'I am done'", true)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); SemaphoreStep.waitForStart("wait/1", b); story.j.jenkins.doQuietDown(true, 0); SemaphoreStep.success("wait/1", null); ((CpsFlowExecution) b.getExecution()).waitForSuspension(); assertTrue(b.isBuilding()); } });