@Override public FlowExecution getOrNull() { try { ListenableFuture<FlowExecution> promise = run().getExecutionPromise(); if (promise.isDone()) { return promise.get(); } } catch (Exception x) { LOGGER.log(/* not important */Level.FINE, null, x); } return null; } @Override public File getRootDir() throws IOException {
private void attachGraphListener(final WorkflowRun build, final GraphListener listener) { build.getExecutionPromise().addListener( new Runnable() { @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()); } } }, Executors.newSingleThreadExecutor()); }
/** * Gets the build going and waits for the workflow to be fully running */ public QueueTaskFuture<WorkflowRun> startBuilding() throws Exception { QueueTaskFuture<WorkflowRun> f = p.scheduleBuild2(0); b = f.waitForStart(); e = (CpsFlowExecution) b.getExecutionPromise().get(); return f; }
/** Sets up a running build that is waiting on input. */ private static WorkflowRun runBasicPauseOnInput(JenkinsRule j, String jobName, int[] jobIdNumber, FlowDurabilityHint durabilityHint) throws Exception { WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, jobName); job.setDefinition(new CpsFlowDefinition("input 'pause'", true)); job.addProperty(new DurabilityHintJobProperty(durabilityHint)); WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get(); ListenableFuture<FlowExecution> listener = run.getExecutionPromise(); FlowExecution exec = listener.get(); while(exec.getCurrentHeads().isEmpty() || (exec.getCurrentHeads().get(0) instanceof FlowStartNode)) { // Wait until input step starts System.out.println("Waiting for input step to begin"); Thread.sleep(50); } while(run.getAction(InputAction.class) == null) { // Wait until input step starts System.out.println("Waiting for input action to get attached to run"); Thread.sleep(50); } Thread.sleep(100L); // A little extra buffer for persistence etc jobIdNumber[0] = run.getNumber(); return run; }
System.out.println("Starting fuzzer job and waiting "+time+" ms before restarting."); WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get(); run.getExecutionPromise().get(); // Ensures run has begun so that it *can* complete cleanly. Thread.sleep(time); return run;
@Issue("JENKINS-50880") @Test public void whenBeforeInputFalse() throws Exception { String whenFile = "whenBeforeInputFalse"; WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, whenFile); p.setDefinition(new CpsFlowDefinition(pipelineSourceFromResources(whenFile), true)); // get the build going, and wait until workflow pauses QueueTaskFuture<WorkflowRun> q = p.scheduleBuild2(0); WorkflowRun b = q.getStartCondition().get(); CpsFlowExecution e = (CpsFlowExecution) b.getExecutionPromise().get(); j.assertBuildStatusSuccess(j.waitForCompletion(b)); j.assertLogNotContains("X-NO-SHOW-X", b); }
@Test public void nativeMethods() throws Exception { p.setDefinition(new CpsFlowDefinition( "@NonCPS def untransformed() {Thread.sleep(Long.MAX_VALUE)}\n" + "def helper() {echo 'sleeping'; /* flush output */ sleep 1; untransformed()}\n" + "helper()", false)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); CpsFlowExecution e = (CpsFlowExecution) b.getExecutionPromise().get(); j.waitForMessage("sleeping", b); do { // wait for the CPS VM to be busy (opposite of waitForSuspension) Thread.sleep(100); } while (!e.blocksRestart()); CpsThreadDump td = e.getThreadDump(); td.print(System.out); assertStackTrace(td.getThreads().get(0), // TODO would like to see untransformed and Thread.sleep here "WorkflowScript.helper(WorkflowScript:2)", "WorkflowScript.run(WorkflowScript:3)"); b.doKill(); }
@Issue("JENKINS-48379") @Test public void simpleInput() throws Exception { WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "simpleInput"); p.setDefinition(new CpsFlowDefinition(pipelineSourceFromResources("simpleInput"), true)); // get the build going, and wait until workflow pauses QueueTaskFuture<WorkflowRun> q = p.scheduleBuild2(0); WorkflowRun b = q.getStartCondition().get(); CpsFlowExecution e = (CpsFlowExecution) b.getExecutionPromise().get(); while (b.getAction(InputAction.class)==null) { e.waitForSuspension(); } // make sure we are pausing at the right state that reflects what we wrote in the program InputAction a = b.getAction(InputAction.class); assertEquals(1, a.getExecutions().size()); InputStepExecution is = a.getExecution("Foo"); assertEquals("Continue?", is.getInput().getMessage()); assertEquals(0, is.getInput().getParameters().size()); assertNull(is.getInput().getSubmitter()); JenkinsRule.WebClient wc = j.createWebClient(); HtmlPage page = wc.getPage(b, a.getUrlName()); j.submit(page.getFormByName(is.getId()), "proceed"); assertEquals(0, a.getExecutions().size()); q.get(); j.assertBuildStatusSuccess(j.waitForCompletion(b)); j.assertLogContains("hello", b); }
@Issue("JENKINS-50880") @Test public void whenBeforeInputTrue() throws Exception { String whenFile = "whenBeforeInputTrue"; WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, whenFile); p.setDefinition(new CpsFlowDefinition(pipelineSourceFromResources(whenFile), true)); // get the build going, and wait until workflow pauses QueueTaskFuture<WorkflowRun> q = p.scheduleBuild2(0); WorkflowRun b = q.getStartCondition().get(); CpsFlowExecution e = (CpsFlowExecution) b.getExecutionPromise().get(); while (b.getAction(InputAction.class)==null) { e.waitForSuspension(); } // make sure we are pausing at the right state that reflects what we wrote in the program InputAction a = b.getAction(InputAction.class); assertEquals(1, a.getExecutions().size()); InputStepExecution is = a.getExecution("Simple-input"); assertEquals("Continue?", is.getInput().getMessage()); assertNull(is.getInput().getSubmitter()); JenkinsRule.WebClient wc = j.createWebClient(); HtmlPage page = wc.getPage(b, a.getUrlName()); j.submit(page.getFormByName(is.getId()), "proceed"); assertEquals(0, a.getExecutions().size()); q.get(); j.assertBuildStatusSuccess(j.waitForCompletion(b)); j.assertLogContains("X-SHOW-X", b); }
CpsFlowExecution e = (CpsFlowExecution) b.getExecutionPromise().get();
CpsFlowExecution e = (CpsFlowExecution) b.getExecutionPromise().get();
assertNotNull(queueTaskFuture); WorkflowRun run = queueTaskFuture.getStartCondition().get(); CpsFlowExecution execution = (CpsFlowExecution) run.getExecutionPromise().get();
CpsFlowExecution e = (CpsFlowExecution) b.getExecutionPromise().get();