diff --git a/CHANGELOG.md b/CHANGELOG.md index c6540a0..ec27782 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ============ * [#219](https://github.com/jenkinsci/ansicolor-plugin/pull/219): Set env var TERM also if a default color map is used - [@tszmytka](https://github.com/tszmytka). +* [#226](https://github.com/jenkinsci/ansicolor-plugin/pull/226): Work around withMaven step not passing on log line metadata - [@tszmytka](https://github.com/tszmytka). * [#225](https://github.com/jenkinsci/ansicolor-plugin/pull/225): Work around logstash-plugin hiding some log lines from ansicolor - [@tszmytka](https://github.com/tszmytka). * Your contribution here. diff --git a/pom.xml b/pom.xml index 7d68bc8..b88b611 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,13 @@ - + 4.0.0 org.jenkins-ci.plugins plugin 4.18 - + ansicolor diff --git a/src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java b/src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java index 2e2804f..5b36644 100644 --- a/src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java +++ b/src/main/java/hudson/plugins/ansicolor/AnsiColorStep.java @@ -128,6 +128,7 @@ private static class AnsiColorExecution extends BodyExecutionCallback { "timestamper.pipeline.GlobalDecorator", "logstash.pipeline.GlobalDecorator", }); + EXTENSIONS_NL.put(StepDescriptor.class, new String[]{"plugins.pipeline.maven"}); } public AnsiColorExecution(String colorMapName) { diff --git a/src/test/java/hudson/plugins/ansicolor/AnsiColorStepTest.java b/src/test/java/hudson/plugins/ansicolor/AnsiColorStepTest.java index dd19b03..30b80d8 100644 --- a/src/test/java/hudson/plugins/ansicolor/AnsiColorStepTest.java +++ b/src/test/java/hudson/plugins/ansicolor/AnsiColorStepTest.java @@ -3,6 +3,7 @@ import hudson.ExtensionList; import hudson.model.queue.QueueTaskFuture; import hudson.plugins.ansicolor.mock.kubernetes.pipeline.SecretsMasker; +import hudson.plugins.ansicolor.mock.plugins.pipeline.maven.WithMavenStep; import hudson.plugins.ansicolor.mock.timestamper.pipeline.GlobalDecorator; import jenkins.model.Jenkins; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; @@ -10,6 +11,7 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun; import org.jenkinsci.plugins.workflow.log.TaskListenerDecorator; import org.jenkinsci.plugins.workflow.steps.DynamicContext; +import org.jenkinsci.plugins.workflow.steps.StepDescriptor; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; @@ -178,6 +180,13 @@ public void willPrintAdditionalNlOnLogstashPlugin() { assertNlsOnRunningPipeline(); } + @Issue("223") + @Test + public void willPrintAdditionalNlOnPipelineMavenPlugin() { + ExtensionList.lookup(StepDescriptor.class).add(0, new WithMavenStep.DescriptorImpl()); + assertNlsOnRunningPipeline(); + } + @Issue("218") @Test public void canUseAndReportGlobalColorMapName() { @@ -257,7 +266,7 @@ public void evaluate() throws Throwable { final String script = "ansiColor('xterm') {\n" + "echo '\033[34mHello\033[0m \033[33mcolorful\033[0m \033[35mworld!\033[0m'" + "}"; - final WorkflowJob project = story.j.jenkins.createProject(WorkflowJob.class, "willPrintAdditionalNlOnKubernetesPlugin"); + final WorkflowJob project = story.j.jenkins.createProject(WorkflowJob.class, "willPrintAdditionalNl"); project.setDefinition(new CpsFlowDefinition(script, true)); story.j.assertBuildStatusSuccess(project.scheduleBuild2(0)); StringWriter writer = new StringWriter(); diff --git a/src/test/java/hudson/plugins/ansicolor/mock/plugins/pipeline/maven/WithMavenStep.java b/src/test/java/hudson/plugins/ansicolor/mock/plugins/pipeline/maven/WithMavenStep.java new file mode 100644 index 0000000..54d7c9d --- /dev/null +++ b/src/test/java/hudson/plugins/ansicolor/mock/plugins/pipeline/maven/WithMavenStep.java @@ -0,0 +1,31 @@ +package hudson.plugins.ansicolor.mock.plugins.pipeline.maven; + +import org.jenkinsci.plugins.workflow.steps.Step; +import org.jenkinsci.plugins.workflow.steps.StepContext; +import org.jenkinsci.plugins.workflow.steps.StepDescriptor; +import org.jenkinsci.plugins.workflow.steps.StepExecution; + +import java.util.Set; + +/** + * Fake step pretending to be a pipeline-maven-plugin component + */ +public class WithMavenStep extends Step { + + @Override + public StepExecution start(StepContext stepContext) throws Exception { + return null; + } + + public static class DescriptorImpl extends StepDescriptor { + @Override + public Set> getRequiredContext() { + return null; + } + + @Override + public String getFunctionName() { + return "fake function"; + } + } +}