@Issue("JENKINS-45455") @Test public void actionPresentOnDeclarative() throws Exception { WorkflowRun r = expect("simplePipeline").go(); assertNotNull(r.getAction(RestartDeclarativePipelineAction.class)); }
@Test public void testDoRestartPipeline() throws Exception { String jobName = "simplePipeline"; WorkflowRun r = expect(jobName).go(); j.waitUntilNoActivity();
@Issue("JENKINS-45455") @Test public void nullStageName() throws Exception { WorkflowRun original = expect(Result.FAILURE, "restart", "simpleRestart") .logContains("Odd numbered build, failing", "This shouldn't show up on second run") .go(); RestartDeclarativePipelineAction action = original.getAction(RestartDeclarativePipelineAction.class); assertNotNull(action); assertTrue(action.isRestartEnabled()); Exception runFailure = null; try { Queue.Item queueItem = action.run(null); // Because we should definitely have thrown an exception in run. assertNull(queueItem); } catch (Exception e) { runFailure = e; } assertNotNull(runFailure); assertTrue(runFailure instanceof IllegalStateException); assertEquals(Messages.RestartDeclarativePipelineAction_NullStageName(), runFailure.getMessage()); }
@Issue("JENKINS-45455") @Test public void stashAndRestart() throws Exception { WorkflowRun original = expect(Result.FAILURE, "restart", "stashAndRestart").go(); WorkflowJob p = original.getParent(); HtmlPage redirect = restartFromStageInUI(original, "restart"); assertNotNull(redirect); assertEquals(p.getAbsoluteUrl(), redirect.getUrl().toString()); j.waitUntilNoActivity(); WorkflowRun b2 = p.getBuildByNumber(2); assertNotNull(b2); j.assertBuildStatusSuccess(b2); j.assertLogContains("Even numbered build, success", b2); j.assertLogContains("Stage \"pre-restart\" skipped due to this build restarting at stage \"restart\"", b2); j.assertLogContains("someFile is some text", b2); }
@Issue("JENKINS-45455") @Test public void emptyStageName() throws Exception { WorkflowRun original = expect(Result.FAILURE, "restart", "simpleRestart") .logContains("Odd numbered build, failing", "This shouldn't show up on second run") .go(); RestartDeclarativePipelineAction action = original.getAction(RestartDeclarativePipelineAction.class); assertNotNull(action); assertTrue(action.isRestartEnabled()); Exception runFailure = null; try { Queue.Item queueItem = action.run(""); // Because we should definitely have thrown an exception in run. assertNull(queueItem); } catch (Exception e) { runFailure = e; } assertNotNull(runFailure); assertTrue(runFailure instanceof IllegalStateException); assertEquals(Messages.RestartDeclarativePipelineAction_NullStageName(), runFailure.getMessage()); }
@Issue("JENKINS-45455") @Test public void notPresentStageName() throws Exception { WorkflowRun original = expect(Result.FAILURE, "restart", "simpleRestart") .logContains("Odd numbered build, failing", "This shouldn't show up on second run") .go(); RestartDeclarativePipelineAction action = original.getAction(RestartDeclarativePipelineAction.class); assertNotNull(action); assertTrue(action.isRestartEnabled()); Exception runFailure = null; try { Queue.Item queueItem = action.run("not-present"); // Because we should definitely have thrown an exception in run. assertNull(queueItem); } catch (Exception e) { runFailure = e; } assertNotNull(runFailure); assertTrue(runFailure instanceof IllegalStateException); assertEquals(Messages.RestartDeclarativePipelineAction_StageNameNotPresent("not-present", original.getFullDisplayName()), runFailure.getMessage()); }
@Issue("JENKINS-45455") @Test public void isRestartedRunCondition() throws Exception { WorkflowRun original = expect("restart", "isRestartedRunCondition") .logContains("This shouldn't show up on second run") .logNotContains("This should only run on restart") .go(); WorkflowJob p = original.getParent(); HtmlPage redirect = restartFromStageInUI(original, "restart"); assertNotNull(redirect); assertEquals(p.getAbsoluteUrl(), redirect.getUrl().toString()); j.waitUntilNoActivity(); WorkflowRun b2 = p.getBuildByNumber(2); assertNotNull(b2); j.assertBuildStatusSuccess(b2); j.assertLogContains("This should only run on restart", b2); j.assertLogNotContains("This shouldn't show up on second run", b2); }
@Issue("JENKINS-45455") @Test public void simpleRestart() throws Exception { WorkflowRun original = expect(Result.FAILURE, "restart", "simpleRestart") .logContains("Odd numbered build, failing", "This shouldn't show up on second run")
@Issue("JENKINS-45455") @Test public void projectNotBuildable() throws Exception { WorkflowRun original = expect(Result.FAILURE, "restart", "simpleRestart") .logContains("Odd numbered build, failing", "This shouldn't show up on second run") .go(); RestartDeclarativePipelineAction action = original.getAction(RestartDeclarativePipelineAction.class); assertNotNull(action); assertTrue(action.isRestartEnabled()); WorkflowJob p = original.getParent(); p.setDisabled(true); Exception runFailure = null; try { Queue.Item queueItem = action.run("restart"); // Because we should definitely have thrown an exception in run. assertNull(queueItem); } catch (Exception e) { runFailure = e; } assertNotNull(runFailure); assertTrue(runFailure instanceof IllegalStateException); assertEquals(Messages.RestartDeclarativePipelineAction_ProjectNotBuildable(p.getFullName()), runFailure.getMessage()); }
@Issue("JENKINS-52261") @Test public void skippedParallelStagesMarkedNotExecuted() throws Exception { WorkflowRun original = expect(Result.FAILURE, "restart", "skippedParallelStagesMarkedNotExecuted") .logContains("Odd numbered build, failing", "This shouldn't show up on second run",
@Issue("JENKINS-45455") @Test public void nestedStagesSkippedOnRestart() throws Exception { WorkflowRun original = expect(Result.FAILURE, "restart", "nestedStagesSkippedOnRestart").go(); WorkflowJob p = original.getParent(); HtmlPage redirect = restartFromStageInUI(original, "restart"); assertNotNull(redirect); assertEquals(p.getAbsoluteUrl(), redirect.getUrl().toString()); j.waitUntilNoActivity(); WorkflowRun b2 = p.getBuildByNumber(2); assertNotNull(b2); j.assertBuildStatusSuccess(b2); j.assertLogContains("Even numbered build, success", b2); j.assertLogContains("Stage \"parallel-pre-restart\" skipped due to this build restarting at stage \"restart\"", b2); j.assertLogContains("Stage \"first-parallel-skipped\" skipped due to this build restarting at stage \"restart\"", b2); j.assertLogContains("Stage \"second-parallel-skipped\" skipped due to this build restarting at stage \"restart\"", b2); j.assertLogContains("Stage \"sequence-pre-restart\" skipped due to this build restarting at stage \"restart\"", b2); j.assertLogContains("Stage \"first-sequence-skipped\" skipped due to this build restarting at stage \"restart\"", b2); j.assertLogContains("Stage \"second-sequence-skipped\" skipped due to this build restarting at stage \"restart\"", b2); j.assertLogContains("Made it to post-restart", b2); }
@Issue("JENKINS-45455") @Test public void sameJenkinsfileNonMultibranch() throws Exception { // This test verifies that the Jenkinsfile is the same across both builds, even if the SCM has changed. // Since we're not a multibranch here, the actual checkout does change, though. WorkflowRun original = expect(Result.FAILURE, "restart", "sameJenkinsfileNonMultibranch").go(); WorkflowJob p = original.getParent(); // Make SCM changes now. sampleRepo.write("Jenkinsfile", pipelineSourceFromResources("restart/sameJenkinsfileNonMultibranchSecond")); sampleRepo.write("newFile", "exists"); sampleRepo.git("add", "Jenkinsfile"); sampleRepo.git("add", "newFile"); sampleRepo.git("commit", "--message=later"); HtmlPage redirect = restartFromStageInUI(original, "restart"); assertNotNull(redirect); assertEquals(p.getAbsoluteUrl(), redirect.getUrl().toString()); j.waitUntilNoActivity(); WorkflowRun b2 = p.getBuildByNumber(2); assertNotNull(b2); j.assertBuildStatusSuccess(b2); j.assertLogContains("Even numbered build, success", b2); j.assertLogContains("Stage \"skip-on-restart\" skipped due to this build restarting at stage \"restart\"", b2); j.assertLogNotContains("Now we're post-restart", b2); j.assertLogNotContains("hello on non-restart", b2); j.assertLogContains("Stage \"post-restart\" skipped due to when conditional", b2); }
@Issue("JENKINS-45455") @Test public void parametersAndRestart() throws Exception { // Initial build passes - we mainly just want it to add the parameters. WorkflowRun original = expect("restart", "parametersAndRestart").go(); WorkflowJob p = original.getParent(); WorkflowRun failing = p.scheduleBuild2(0, new ParametersAction(new BooleanParameterValue("flag", false), new StringParameterValue("someParam", "changed"))).waitForStart(); j.assertBuildStatus(Result.FAILURE, j.waitForCompletion(failing)); HtmlPage redirect = restartFromStageInUI(failing, "restart"); assertNotNull(redirect); assertEquals(p.getAbsoluteUrl(), redirect.getUrl().toString()); j.waitUntilNoActivity(); WorkflowRun b3 = p.getBuildByNumber(3); assertNotNull(b3); j.assertBuildStatusSuccess(b3); j.assertLogContains("Odd numbered build, success", b3); j.assertLogContains("Stage \"pre-restart\" skipped due to this build restarting at stage \"restart\"", b3); j.assertLogContains("Flag is false", b3); j.assertLogContains("someParam is changed", b3); j.assertLogContains("otherParam is should not change", b3); j.assertLogNotContains("hello on non-restart", b3); }