/** * Asserts that the console output of the build does not contain the given substring. */ public void assertLogNotContains(String substring, Run run) throws IOException { assertThat(getLog(run), not(containsString(substring))); }
/** * Waits for a build log to contain a specified string. * Useful in conjunction with {@link BuildWatcher}. * @return the same build, once it does * @since 1.607 */ public <R extends Run<?,?>> R waitForMessage(String message, R r) throws IOException, InterruptedException { while (!getLog(r).contains(message)) { if (!r.isLogUpdated()) { assertLogContains(message, r); // should now fail } Thread.sleep(100); } return r; }
/** * Asserts that the console output of the build contains the given substring. */ public void assertLogContains(String substring, Run run) throws IOException { assertThat(getLog(run), containsString(substring)); }
/** * Asserts that the outcome of the build is a specific outcome. */ public <R extends Run> R assertBuildStatus(Result status, R r) throws Exception { if(status==r.getResult()) return r; // dump the build output in failure message (in case BuildWatcher is not being used) String msg = "unexpected build status; build log was:\n------\n" + getLog(r) + "\n------\n"; assertThat(msg, r.getResult(), is(status)); return r; }
@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 { 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 { 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); if (run.getExecution() instanceof CpsFlowExecution) { CpsFlowExecution cpsFlow = (CpsFlowExecution)(run.getExecution()); cpsFlow.pause(true); long timeout = System.nanoTime()+TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS); while(System.nanoTime() < timeout && !cpsFlow.isPaused()) { Thread.sleep(100L); } } } });
@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); } });
@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); } });
/** * Split arguments between meta step and state */ @Issue("JENKINS-29922") @Test public void dollar_class_must_die2() throws Exception { WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "die2"); p.setDefinition(new CpsFlowDefinition("california ocean:'pacific', mountain:'sierra', moderate:true", true)); assertThat(JenkinsRule.getLog(r.assertBuildStatusSuccess(p.scheduleBuild2(0))).replace("\r\n", "\n"), containsString("Introducing california\nCalifornia from pacific to sierra")); }
@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); if (run.getExecution() instanceof CpsFlowExecution) { // Pause and unPause to force persistence CpsFlowExecution cpsFlow = (CpsFlowExecution)(run.getExecution()); cpsFlow.pause(true); long timeout = System.nanoTime()+TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS); while(System.nanoTime() < timeout && !cpsFlow.isPaused()) { Thread.sleep(100L); } nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution())); nodesOut.sort(FlowScanningUtils.ID_ORDER_COMPARATOR); cpsFlow.pause(false); timeout = System.nanoTime()+TimeUnit.NANOSECONDS.convert(5, TimeUnit.SECONDS); while(System.nanoTime() < timeout && cpsFlow.isPaused()) { Thread.sleep(100L); } // Ensures we're marked as can-not-resume cpsFlow.persistedClean = false; cpsFlow.saveOwner(); } } });
/** * Split arguments between meta step and state, when argument is colliding */ @Issue("JENKINS-29922") @Test public void dollar_class_must_die_colliding_argument() throws Exception { WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "die5"); p.setDefinition(new CpsFlowDefinition("newYork motto:'Empire', moderate:true", true)); WorkflowRun run = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); assertThat(JenkinsRule.getLog(run).replace("\r\n", "\n"), containsString("Introducing newYork\nThe Empire State")); r.assertLogNotContains("New York can be moderate in spring or fall", run); }
@Override public void evaluate() throws Throwable { Jenkins jenkins = story.j.jenkins; WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY); run.getParent().setResumeBlocked(true); FlowExecution exec = run.getExecution(); if (exec instanceof CpsFlowExecution) { assert ((CpsFlowExecution) exec).getStorage().isPersistedFully(); } logStart[0] = JenkinsRule.getLog(run); nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution())); nodesOut.sort(FlowScanningUtils.ID_ORDER_COMPARATOR); } });
@Override public void evaluate() throws Throwable { Jenkins jenkins = story.j.jenkins; WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY); run.getParent().setResumeBlocked(false); FlowExecution exec = run.getExecution(); if (exec instanceof CpsFlowExecution) { assert ((CpsFlowExecution) exec).getStorage().isPersistedFully(); } logStart[0] = JenkinsRule.getLog(run); nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution())); nodesOut.sort(FlowScanningUtils.ID_ORDER_COMPARATOR); run.getParent().setResumeBlocked(true); } });
@Override public void evaluate() throws Throwable { for (int i=0; i<durabilityHints.length; i++) { WorkflowJob j = jobs[i]; try{ WorkflowRun run = j.getLastBuild(); verifySucceededCleanly(story.j.jenkins, run); Assert.assertEquals(durabilityHints[i], run.getExecution().getDurabilityHint()); Assert.assertEquals(logOutput[i], JenkinsRule.getLog(run)); assertHasTimingAction(run.getExecution()); } catch (AssertionError ae) { System.out.println("Error with durability level: "+durabilityHints[i]); throw ae; } } } });
@Override public void evaluate() throws Throwable { int i = 1; for (FlowDurabilityHint hint : durabilityHints) { try{ WorkflowRun run = createAndRunBasicJob(story.j.jenkins, "basicJob-"+hint.toString(), hint, i); jobs[i-1] = run.getParent(); SemaphoreStep.success("halt/"+i++,Result.SUCCESS); story.j.waitForCompletion(run); story.j.assertBuildStatus(Result.SUCCESS, run); logOutput[i-2] = JenkinsRule.getLog(run); assertHasTimingAction(run.getExecution()); } catch (AssertionError ae) { System.out.println("Error with durability level: "+hint); throw ae; } } } });
@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 = jenkins.createProject(WorkflowJob.class, "p"); jenkins.getWorkspaceFor(p).child("test.groovy").write( "def answer(i) { return i*2; }\n" + "def foo(body) {\n" + " def i = body()\n" + " semaphore 'watchA'\n" + " return answer(i);\n" + "}\n" + "return this;", null); p.setDefinition(new CpsFlowDefinition( "node {\n" + " println 'started'\n" + " def o = load 'test.groovy'\n" + " println 'o=' + o.foo({21})\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("watchA/1", b); assertTrue(JenkinsRule.getLog(b), b.isBuilding()); } });
@Bug(5396) @Test public void tags() throws Exception { m.hg(repo, "init"); m.touchAndCommit(repo, "f1"); m.touchAndCommit(repo, "f2"); m.hg(repo, "tag", "release"); m.touchAndCommit(repo, "f3"); FreeStyleProject p = j.createFreeStyleProject(); p.setScm(new MercurialSCM(hgInstallation(), repo.getPath(), MercurialSCM.RevisionType.TAG, "release", null, null, null, false, null)); FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); FilePath ws = b.getWorkspace(); assertTrue(ws.child("f1").exists()); assertTrue(ws.child("f2").exists()); assertFalse(ws.child("f3").exists()); m.hg(repo, "tag", "--force", "release"); b = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); assertTrue(JenkinsRule.getLog(b), ws.child("f3").exists()); }