Send the tail of the log to Logstash.
+Send the tail of the log to Logstash.
+ Any changes to the result, that happen after the notifier is run are not reflected in the upload.
+ If the a project enables uploading the log via a JobProperty in line mode as well, the Notifier gets disabled.
+
The maximum number of log lines to send to Logstash.
If the log is bigger than this, only the most recent lines are sent.
- -1 indicates there is no maximum (for very large logs, consider using the Logstash Job Property instead).
, R extends AbstractBuild
> extends Run
{
+
Result result;
MockRun(P job) throws IOException {
@@ -136,6 +138,8 @@ public void performSuccess() throws Exception {
verify(mockListener).getLogger();
verify(mockWriter).writeBuildLog(3);
verify(mockWriter).isConnectionBroken();
+ verify(mockBuild).getAction(LogstashMarkerAction.class);
+ verify(mockBuild).addAction(any(LogstashMarkerAction.class));
assertEquals("Errors were written", "", errorBuffer.toString());
@@ -172,6 +176,8 @@ public void performBadWriterDoNotFailBuild() throws Exception {
verify(mockListener).getLogger();
verify(mockWriter).writeBuildLog(3);
verify(mockWriter).isConnectionBroken();
+ verify(mockBuild).getAction(LogstashMarkerAction.class);
+ verify(mockBuild).addAction(any(LogstashMarkerAction.class));
assertEquals("Error was not written", "Mocked Constructor failure", errorBuffer.toString());
}
@@ -213,6 +219,8 @@ public void performBadWriterDoFailBuild() throws Exception {
verify(mockListener).getLogger();
verify(mockWriter).writeBuildLog(3);
verify(mockWriter, times(2)).isConnectionBroken();
+ verify(mockBuild).getAction(LogstashMarkerAction.class);
+ verify(mockBuild).addAction(any(LogstashMarkerAction.class));
assertEquals("Error was not written", "Mocked Constructor failure", errorBuffer.toString());
}
@@ -264,6 +272,8 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
verify(mockListener).getLogger();
verify(mockWriter).writeBuildLog(3);
verify(mockWriter, times(3)).isConnectionBroken();
+ verify(mockBuild).getAction(LogstashMarkerAction.class);
+ verify(mockBuild).addAction(any(LogstashMarkerAction.class));
assertThat("Wrong error message", errorBuffer.toString(), containsString(errorMsg));
}
@@ -286,6 +296,8 @@ public void performAllLines() throws Exception {
verify(mockListener).getLogger();
verify(mockWriter).writeBuildLog(-1);
verify(mockWriter, times(2)).isConnectionBroken();
+ verify(mockBuild).getAction(LogstashMarkerAction.class);
+ verify(mockBuild).addAction(any(LogstashMarkerAction.class));
assertEquals("Errors were written", "", errorBuffer.toString());
}
@@ -308,6 +320,8 @@ public void performZeroLines() throws Exception {
verify(mockListener).getLogger();
verify(mockWriter).writeBuildLog(0);
verify(mockWriter, times(2)).isConnectionBroken();
+ verify(mockBuild).getAction(LogstashMarkerAction.class);
+ verify(mockBuild).addAction(any(LogstashMarkerAction.class));
assertEquals("Errors were written", "", errorBuffer.toString());
}
diff --git a/src/test/java/jenkins/plugins/logstash/PipelineTest.java b/src/test/java/jenkins/plugins/logstash/PipelineTest.java
index 83f45724..fa0b2bce 100644
--- a/src/test/java/jenkins/plugins/logstash/PipelineTest.java
+++ b/src/test/java/jenkins/plugins/logstash/PipelineTest.java
@@ -1,6 +1,7 @@
package jenkins.plugins.logstash;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.util.List;
@@ -70,6 +71,24 @@ public void logstashSendNotifier() throws Exception
assertThat(data.getString("result"),equalTo("SUCCESS"));
}
+ @Test
+ public void logstashSendNotifierAtEnd() throws Exception
+ {
+ WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
+ p.setDefinition(new CpsFlowDefinition("node {" +
+ "echo 'Message'\n" +
+ "currentBuild.result = 'SUCCESS'\n" +
+ "step([$class: 'LogstashNotifier', failBuild: true, maxLines: 5, runNotifierAtEnd: true])" +
+ "}", true));
+ j.assertBuildStatusSuccess(p.scheduleBuild2(0).get());
+ List