From 416990693bd229527684b2302fd9857432feccbc Mon Sep 17 00:00:00 2001 From: Devin Nusbaum Date: Fri, 3 Mar 2023 16:17:55 -0500 Subject: [PATCH 1/5] Flush overall Pipeline log stream when shutting down Jenkins --- .../org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java b/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java index 8550caf86..31b63a965 100644 --- a/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java +++ b/plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java @@ -1694,6 +1694,7 @@ public void pause(final boolean v) throws IOException { LOGGER.log(Level.WARNING, null, t); } }); + cpsExec.getOwner().getListener().getLogger().close(); } } catch (Exception ex) { LOGGER.log(Level.WARNING, "Error persisting Pipeline execution at shutdown: "+((CpsFlowExecution) execution).owner, ex); From 479665f0d0196b0a75fa14a0d40cea7fc0b7cee0 Mon Sep 17 00:00:00 2001 From: Devin Nusbaum Date: Fri, 3 Mar 2023 17:39:35 -0500 Subject: [PATCH 2/5] Add regression test using RealJenkinsRule --- .../cps/CpsFlowDefinitionRJRTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionRJRTest.java b/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionRJRTest.java index f1ef48d35..d09c57985 100644 --- a/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionRJRTest.java +++ b/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionRJRTest.java @@ -1,6 +1,7 @@ package org.jenkinsci.plugins.workflow.cps; import org.jenkinsci.plugins.workflow.job.WorkflowJob; +import org.jenkinsci.plugins.workflow.job.WorkflowRun; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; @@ -21,4 +22,26 @@ private static void doesItSmoke(JenkinsRule r) throws Exception { p.setDefinition(new CpsFlowDefinition("print Jenkins.get().getRootDir().toString()", false)); r.assertBuildStatusSuccess(p.scheduleBuild2(0)); } + + @Test + public void flushLogsOnShutdown() throws Throwable { + rjr.then(CpsFlowDefinitionRJRTest::flushLogsOnShutdownPreRestart); + rjr.then(CpsFlowDefinitionRJRTest::flushLogsOnShutdownPostRestart); + } + + private static void flushLogsOnShutdownPreRestart(JenkinsRule r) throws Exception { + WorkflowJob p = r.createProject(WorkflowJob.class, "p"); + p.setDefinition(new CpsFlowDefinition("sleep 10\n", true)); + WorkflowRun b = p.scheduleBuild2(0).waitForStart(); + r.waitForMessage("Sleeping for 10 sec", b); + r.jenkins.doQuietDown(); + } + + private static void flushLogsOnShutdownPostRestart(JenkinsRule r) throws Exception { + WorkflowJob p = r.jenkins.getItemByFullName("p", WorkflowJob.class); + WorkflowRun b = p.getLastBuild(); + r.assertBuildStatusSuccess(r.waitForCompletion(b)); + r.assertLogContains("Resuming build at ", b); + r.assertLogContains("Pausing (Preparing for shutdown)", b); + } } From c144a2bbd8fc7a6355241f7b0bcf91b7fdaddba8 Mon Sep 17 00:00:00 2001 From: Devin Nusbaum Date: Mon, 6 Mar 2023 13:24:55 -0500 Subject: [PATCH 3/5] Enhance logging to diagnose CpsFlowDefinitionRJRTest.flushLogsOnShutdown failure on Windows --- plugin/pom.xml | 1 + .../plugins/workflow/cps/CpsFlowDefinitionRJRTest.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/plugin/pom.xml b/plugin/pom.xml index 3f54de928..c67164d77 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -45,6 +45,7 @@ 18.13.0 8.19.3 1.22.19 + 1926.v9b_323a_4da_421 diff --git a/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionRJRTest.java b/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionRJRTest.java index d09c57985..4083adb3f 100644 --- a/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionRJRTest.java +++ b/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionRJRTest.java @@ -1,5 +1,6 @@ package org.jenkinsci.plugins.workflow.cps; +import java.util.logging.Level; import org.jenkinsci.plugins.workflow.job.WorkflowJob; import org.jenkinsci.plugins.workflow.job.WorkflowRun; import org.junit.Rule; @@ -25,6 +26,7 @@ private static void doesItSmoke(JenkinsRule r) throws Exception { @Test public void flushLogsOnShutdown() throws Throwable { + rjr.withLogger(CpsFlowExecution.class, Level.FINER); rjr.then(CpsFlowDefinitionRJRTest::flushLogsOnShutdownPreRestart); rjr.then(CpsFlowDefinitionRJRTest::flushLogsOnShutdownPostRestart); } From d49313ec93ea1c1b3914c860c5ccaf63a2fd524f Mon Sep 17 00:00:00 2001 From: Devin Nusbaum Date: Mon, 6 Mar 2023 14:24:45 -0500 Subject: [PATCH 4/5] Update Jenkins version to try to diagnose CpsFlowDefinitionRJRTest.flushLogsOnShutdown failure on Windows --- plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/pom.xml b/plugin/pom.xml index c67164d77..911265c58 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -45,7 +45,7 @@ 18.13.0 8.19.3 1.22.19 - 1926.v9b_323a_4da_421 + 2.391 From 6888d8293b0dbdd1dfcac86e0d6700a56b2b4f2b Mon Sep 17 00:00:00 2001 From: Devin Nusbaum Date: Mon, 6 Mar 2023 16:17:54 -0500 Subject: [PATCH 5/5] Skip CpsFlowDefinitionRJRTest.flushLogsOnShutdown on Windows for now --- plugin/pom.xml | 1 - .../plugins/workflow/cps/CpsFlowDefinitionRJRTest.java | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/pom.xml b/plugin/pom.xml index 911265c58..3f54de928 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -45,7 +45,6 @@ 18.13.0 8.19.3 1.22.19 - 2.391 diff --git a/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionRJRTest.java b/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionRJRTest.java index 4083adb3f..d4de62386 100644 --- a/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionRJRTest.java +++ b/plugin/src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinitionRJRTest.java @@ -1,8 +1,10 @@ package org.jenkinsci.plugins.workflow.cps; +import hudson.Functions; import java.util.logging.Level; import org.jenkinsci.plugins.workflow.job.WorkflowJob; import org.jenkinsci.plugins.workflow.job.WorkflowRun; +import org.junit.Assume; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; @@ -26,6 +28,7 @@ private static void doesItSmoke(JenkinsRule r) throws Exception { @Test public void flushLogsOnShutdown() throws Throwable { + Assume.assumeFalse("RealJenkinsRule does not shut down Jenkins cleanly on Windows, see https://github.com/jenkinsci/jenkins-test-harness/pull/559", Functions.isWindows()); rjr.withLogger(CpsFlowExecution.class, Level.FINER); rjr.then(CpsFlowDefinitionRJRTest::flushLogsOnShutdownPreRestart); rjr.then(CpsFlowDefinitionRJRTest::flushLogsOnShutdownPostRestart);