@Override public boolean shouldCalculateCulprits() { return isBuilding() || culprits == null; }
@Override public boolean isLogUpdated() { return isBuilding(); // there is no equivalent to a post-production state for flows }
@Restricted(DoNotUse.class) // Jelly public boolean hasAllowKill() { return isBuilding() && allowKill; }
@Restricted(DoNotUse.class) // Jelly public boolean hasAllowTerm() { return isBuilding() && allowTerm; }
@Override @CheckForNull public Set<String> getCulpritIds() { if (shouldCalculateCulprits()) { HashSet<String> tempCulpritIds = new HashSet<>(); for (User u : getCulprits()) { tempCulpritIds.add(u.getId()); } if (isBuilding()) { return ImmutableSortedSet.copyOf(tempCulpritIds); } else { culprits = ImmutableSortedSet.copyOf(tempCulpritIds); } } return culprits; }
private static void assertBuildNotHung(@Nonnull RestartableJenkinsRule story, @Nonnull WorkflowRun run, int timeOutMillis) throws Exception { if (run.isBuilding()) { story.j.waitUntilNoActivityUpTo(timeOutMillis); } }
public void assertThatWorkflowIsSuspended(WorkflowRun b, CpsFlowExecution e) throws Exception { e.waitForSuspension(); // it should be in the suspended state assert b.isBuilding(); }
public void assertBuildCompletedSuccessfully(WorkflowRun b) throws Exception { assert !b.isBuilding(); story.j.assertBuildStatusSuccess(b); }
/** Immediately kills the build. */ @RequirePOST public void doKill() { checkPermission(Item.CANCEL); if (!isBuilding() || /* probably redundant, but just to be sure */ execution == null) { return; } if (listener != null) { listener.getLogger().println("Hard kill!"); } execution = null; // ensures isInProgress returns false FlowInterruptedException suddenDeath = new FlowInterruptedException(Result.ABORTED); finish(Result.ABORTED, suddenDeath); executionPromise.setException(suddenDeath); // TODO CpsFlowExecution.onProgramEnd does some cleanup which we cannot access here; perhaps need a FlowExecution.halt(Throwable) API? }
/** 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); }
@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; } } });
@Override public void evaluate() throws Throwable { Logger LOGGER = Logger.getLogger("org.jenkinsci.plugins.workflow"); LOGGER.setLevel(Level.FINE); Handler handler = new ConsoleHandler(); handler.setLevel(Level.ALL); LOGGER.addHandler(handler); WorkflowJob p = story.j.jenkins.getItemByFullName("p", WorkflowJob.class); WorkflowRun b = p.getLastBuild(); assertTrue(b.isBuilding()); story.j.waitForMessage("Cannot restore BadThing", b); b.getExecutor().interrupt(); story.j.assertBuildStatus(Result.ABORTED, story.j.waitForCompletion(b)); } });
static void assertCleanInProgress(WorkflowRun run) throws Exception { Assert.assertTrue(run.isBuilding()); Assert.assertNull(run.getResult()); FlowExecution fe = run.getExecution(); AtomicBoolean hasExecutionInList = new AtomicBoolean(false); FlowExecutionList.get().forEach(f -> { if (fe != null && f == fe) { hasExecutionInList.set(true); } }); if (!hasExecutionInList.get()) { Assert.fail("Build completed but should still show in FlowExecutionList"); } CpsFlowExecution cpsExec = (CpsFlowExecution)fe; Assert.assertFalse(cpsExec.isComplete()); Assert.assertEquals(Boolean.FALSE, cpsExec.done); Assert.assertFalse(cpsExec.getCurrentHeads().get(0) instanceof FlowEndNode); Assert.assertTrue(cpsExec.startNodes != null && !cpsExec.startNodes.isEmpty()); }
@Override public void evaluate() throws Throwable { p = jenkins().createProject(WorkflowJob.class, "demo"); p.setDefinition(new CpsFlowDefinition("node { persistenceProblem() }", false)); startBuilding(); waitForWorkflowToSuspend(); // TODO: let the ripple effect of a failure run to the completion. while (b.isBuilding()) try { waitForWorkflowToSuspend(); } catch (Exception x) { // ignore persistence failure String message = x.getMessage(); if (message == null || !message.contains("Failed to persist")) { throw x; } } story.j.assertBuildStatus(Result.FAILURE, b); story.j.assertLogContains("java.lang.RuntimeException: testing the forced persistence failure behaviour", b); } });
@Override public void evaluate() throws Throwable { p = jenkins().createProject(WorkflowJob.class, "demo"); p.setDefinition(new CpsFlowDefinition("semaphore 'wait'", false)); startBuilding(); SemaphoreStep.waitForStart("wait/1", b); assertTrue(b.isBuilding()); liveness(); } });
@Override public void evaluate() throws Throwable { p = jenkins().createProject(WorkflowJob.class, "demo"); p.setDefinition(new CpsFlowDefinition( "int count=0;\n" + "retry(3) {\n" + " semaphore 'wait'\n" + " if (count++ < 2) {\n" + // forcing retry " error 'died'\n" + " }\n" + "}", false)); startBuilding(); SemaphoreStep.waitForStart("wait/1", b); assertTrue(b.isBuilding()); } });
@Override public void evaluate() throws Throwable { WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p"); jenkins.getWorkspaceFor(p).child("test.groovy").write( "def answer(i) { return i*2; }\n" + "def i=21;\n" + "semaphore 'watchB'\n" + "return answer(i);\n", null); p.setDefinition(new CpsFlowDefinition( "node {\n" + " println 'started'\n" + " def o = load 'test.groovy'\n" + " println 'o=' + o;\n" + "}", false)); // get the build going WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get(); // wait until the executor gets assigned and the execution pauses SemaphoreStep.waitForStart("watchB/1", b); assertTrue(JenkinsRule.getLog(b), b.isBuilding()); } });
@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()); } });
@Override public void evaluate() throws Throwable { jenkins().setSecurityRealm(story.j.createDummySecurityRealm()); jenkins().save(); QueueItemAuthenticatorConfiguration.get().getAuthenticators().add(new MockQueueItemAuthenticator(Collections.singletonMap("demo", User.getById("someone", true).impersonate()))); p = jenkins().createProject(WorkflowJob.class, "demo"); p.setDefinition(new CpsFlowDefinition("checkAuth()", false)); ScriptApproval.get().preapproveAll(); startBuilding(); waitForWorkflowToSuspend(); assertTrue(b.isBuilding()); story.j.waitForMessage("running as someone", b); CheckAuth.finish(false); waitForWorkflowToSuspend(); assertTrue(b.isBuilding()); story.j.waitForMessage("still running as someone", b); } });
@Override public void evaluate() throws Throwable { WorkflowJob p = story.j.jenkins.getItemByFullName("p", WorkflowJob.class); WorkflowRun b = p.getLastBuild(); assertTrue(b.isBuilding()); CpsFlowExecution e = (CpsFlowExecution) b.getExecution(); assertTrue(e.isPaused()); JenkinsRule.WebClient wc = story.j.createWebClient(); WebRequest wrs = new WebRequest(wc.createCrumbedUrl(b.getUrl() + PauseUnpauseAction.URL + "/toggle"), HttpMethod.POST); wc.login("dev").getPage(wrs); assertFalse(e.isPaused()); story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)); assertFalse(e.isPaused()); } });