-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flush overall Pipeline log stream when shutting down Jenkins #669
Changes from 2 commits
4169906
479665f
c144a2b
d49313e
6888d82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1694,6 +1694,7 @@ public void pause(final boolean v) throws IOException { | |
LOGGER.log(Level.WARNING, null, t); | ||
} | ||
}); | ||
cpsExec.getOwner().getListener().getLogger().close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think
|
||
} | ||
} catch (Exception ex) { | ||
LOGGER.log(Level.WARNING, "Error persisting Pipeline execution at shutdown: "+((CpsFlowExecution) execution).owner, ex); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
Comment on lines
+49
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first assertion here passes with or without the fix, since that message is printed after the restart. However, the second assertion is printed right before Jenkins shuts down, and it is missing from the log if you revert the fix. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also just
flush
(I tested both options), but I'm not really sure that it matters either way.