Refine search
@Issue("JENKINS-42027") @Test public void globalConfigPersists() throws Exception { story.addStep(new Statement() { @Override public void evaluate() throws Throwable { GlobalConfig.get().setDockerLabel("config_docker"); GlobalConfig.get().save(); } }); story.addStep(new Statement() { @Override public void evaluate() throws Throwable { assertEquals("config_docker", GlobalConfig.get().getDockerLabel()); } }); }
/** Verify that if the master dies messily and we're not durable against that, build fails cleanly. */ @Test public void testDurableAgainstCleanRestartFailsWithDirtyShutdown() throws Exception { final String[] logStart = new String[1]; story.addStepWithDirtyShutdown(new Statement() { @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); } }); story.addStep(new Statement() { @Override public void evaluate() throws Throwable { WorkflowRun run = story.j.jenkins.getItemByFullName("durableAgainstClean", WorkflowJob.class).getLastBuild(); verifyFailedCleanly(story.j.jenkins, run); story.j.assertLogContains(logStart[0], run); } }); }
private void run() throws Throwable { HudsonHomeLoader loader = () -> home; // run each step inside its own JenkinsRule for (Map.Entry<Statement, Boolean> entry : steps.entrySet()) { Statement step = entry.getKey(); j = createJenkinsRule(description).with(loader); try { j.apply(step, description).evaluate(); if (!entry.getValue()) { Assert.fail("The current JenkinsRule should have failed to start Jenkins."); } } catch (Exception e) { if(entry.getValue()) { throw e; } // Failure ignored as requested } } }
public void step(final Closure c) { addStep(new Statement() { @Override public void evaluate() throws Throwable { c.call(j); } }); }
@Issue("JENKINS-50888") // Tried to modify build without lazy load being triggered @Test public void modifyBeforeLazyLoad() { story.then(r -> { // Normal build WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("echo 'dosomething'", true)); r.buildAndAssertSuccess(p); }); story.then(r -> { // But wait, we try to modify the build without loading the execution WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class); WorkflowRun b = p.getBuildByNumber(1); b.setDescription("Bob"); b.save(); // Before the JENKINS-50888 fix this would trigger an IOException }); story.then( r-> { // Verify that the FlowExecutionOwner can trigger lazy-load correctly WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class); WorkflowRun b = p.getBuildByNumber(1); Assert.assertEquals("Bob", b.getDescription()); Assert.assertEquals("4", b.getExecution().getCurrentHeads().get(0).getId()); }); } }
/** Verify that if the master dies messily and FlowNode storage is lost entirely we fail the build cleanly. */ @Test @Issue("JENKINS-48824") public void testDurableAgainstCleanRestartFailsWithBogusStorageFile() throws Exception { final String[] logStart = new String[1]; story.addStepWithDirtyShutdown(new Statement() { @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 } } }); story.addStep(new Statement() { @Override public void evaluate() throws Throwable { WorkflowRun run = story.j.jenkins.getItemByFullName("durableAgainstClean", WorkflowJob.class).getLastBuild(); verifyFailedCleanly(story.j.jenkins, run); story.j.assertLogContains(logStart[0], run); } }); }
@Test /** Build okay but program fails to load */ public void inProgressButProgramLoadFailure() throws Exception { final int[] build = new int[1]; story.thenWithHardShutdown( j -> { WorkflowRun run = runBasicPauseOnInput(j, DEFAULT_JOBNAME, build); CpsFlowExecution cpsExec = (CpsFlowExecution)(run.getExecution()); cpsExec.getProgramDataFile().delete(); }); story.then( j->{ WorkflowJob r = j.jenkins.getItemByFullName(DEFAULT_JOBNAME, WorkflowJob.class); WorkflowRun run = r.getBuildByNumber(build[0]); assertCompletedCleanly(run); }); }
@Test public void inProgressNormal() throws Exception { final int[] build = new int[1]; story.then( j -> { WorkflowRun run = runBasicPauseOnInput(j, DEFAULT_JOBNAME, build); }); story.then( j->{ WorkflowJob r = j.jenkins.getItemByFullName(DEFAULT_JOBNAME, WorkflowJob.class); WorkflowRun run = r.getBuildByNumber(build[0]); assertCleanInProgress(run); InputStepExecution exec = getInputStepExecution(run, "pause"); exec.doProceedEmpty(); j.waitForCompletion(run); assertCompletedCleanly(run); Assert.assertEquals(Result.SUCCESS, run.getResult()); }); }
@Override public void evaluate() throws Throwable { s.run(j); simulateAbruptShutdown(); } });
/** * Run one Jenkins session and shut down. * @since 2.24 */ public void then(final Step s) { addStep(new Statement() { @Override public void evaluate() throws Throwable { s.run(j); } }); }
@Issue("JENKINS-53709") @Test public void popContextVarsOnBodyCompletion() { rr.then(r -> { DumbSlave s = r.createOnlineSlave(); WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo"); p.setDefinition(new CpsFlowDefinition("node('" + s.getNodeName() + "') {\n" + " parallel one: {\n" + " echo '" + s.getNodeName() + "'\n" + " }\n" + "}\n" + "semaphore 'wait'\n", true)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); SemaphoreStep.waitForStart("wait/1", b); r.jenkins.removeNode(s); }); rr.then(r -> { WorkflowRun b = r.jenkins.getItemByFullName("demo", WorkflowJob.class).getBuildByNumber(1); SemaphoreStep.waitForStart("wait/1", b); SemaphoreStep.success("wait/1", null); while (b.isBuilding()) { // Before the fix for JENKINS-53709, the job hangs forever while attempting to rehydrate the agent. r.assertLogNotContains("Jenkins doesn’t have label", b); Thread.sleep(100); } r.assertBuildStatusSuccess(b); }); }
@Test @Issue("JENKINS-49961") public void testResumeBlockedAddedAfterRunStart() throws Exception { final String jobName = "survivesEverything"; final List<FlowNode> nodesOut = new ArrayList<FlowNode>(); story.addStepWithDirtyShutdown(new Statement() { @Override public void evaluate() throws Throwable { story.addStep(new Statement() { @Override public void evaluate() throws Throwable {
@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); }); }
rr.then(jenkins -> { WorkflowJob p = jenkins.createProject(WorkflowJob.class); p.setDefinition(new CpsFlowDefinition("synchronousExceptionInBody()",true));
@Override public void evaluate() throws Throwable { j.jenkins.getInjector().injectMembers(step); j.jenkins.getInjector().injectMembers(target); step.evaluate(); simulateAbruptShutdown(); } }, true);
@Issue("JENKINS-34645") @Test public void stringSplit() { rr.addStep(new Statement() { @Override public void evaluate() throws Throwable { WorkflowJob p = rr.j.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("for (x in 'a;b'.split(';')) {sleep 1; echo(/running in $x/)}", true)); rr.j.assertLogContains("running in b", rr.j.buildAndAssertSuccess(p)); } }); }
public void thenDoesNotStart() { addStep(new Statement() { @Override public void evaluate() throws Throwable { throw new IllegalStateException("should have failed before reaching here."); } }, false); }
@Issue("JENKINS-34637") @Test public void currentExecutions() throws Exception { rr.then(jenkins -> { WorkflowJob p = jenkins.createProject(WorkflowJob.class); p.setDefinition(new CpsFlowDefinition("parallel main: {retainsBody {parallel a: {retainsBody {semaphore 'a'}}, b: {retainsBody {semaphore 'b'}}}}, aside: {semaphore 'c'}", true));
public void testDurableAgainstCleanRestartResetsCleanlyPersistedFlag() throws Exception { final String jobName = "durableAgainstClean"; story.addStep(new Statement() { @Override public void evaluate() throws Throwable { story.addStepWithDirtyShutdown(new Statement() { @Override public void evaluate() throws Throwable { story.addStep(new Statement() { @Override public void evaluate() throws Throwable {
@Test /** Build okay but then the start nodes get screwed up */ public void inProgressButStartBlocksLost() throws Exception { final int[] build = new int[1]; story.thenWithHardShutdown( j -> { WorkflowRun run = runBasicPauseOnInput(j, DEFAULT_JOBNAME, build); CpsFlowExecution cpsExec = (CpsFlowExecution)(run.getExecution()); cpsExec.startNodes.push(new FlowStartNode(cpsExec, cpsExec.iotaStr())); run.save(); }); story.then( j->{ WorkflowJob r = j.jenkins.getItemByFullName(DEFAULT_JOBNAME, WorkflowJob.class); WorkflowRun run = r.getBuildByNumber(build[0]); assertCompletedCleanly(run); }); }