Skip to content
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

#223 Work around withMaven step not passing on log line metadata #226

Merged
merged 3 commits into from
May 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.18</version>
<relativePath />
<relativePath/>
</parent>

<artifactId>ansicolor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion src/test/java/hudson/plugins/ansicolor/AnsiColorStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
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;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<? extends Class<?>> getRequiredContext() {
return null;
}

@Override
public String getFunctionName() {
return "fake function";
}
}
}