Skip to content
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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,11 @@
<artifactId>scm-api</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>generic-environment-filters</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.tasks.BatchFile;
import hudson.tasks.Shell;
import io.jenkins.plugins.generic_environment_filters.RemoveSpecificVariablesFilter;
import io.jenkins.plugins.generic_environment_filters.VariableContributingFilter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
Expand All @@ -54,6 +56,7 @@
import java.util.logging.Level;
import java.util.logging.LogRecord;
import javax.annotation.CheckForNull;
import jenkins.tasks.filters.EnvVarsFilterGlobalConfiguration;
import jenkins.util.JenkinsJVM;
import org.apache.commons.lang.StringUtils;

Expand Down Expand Up @@ -724,6 +727,23 @@ private static final class HelloNote extends ConsoleNote<Run<?, ?>> {
j.waitForMessage("Timeout has been exceeded", b); // TODO assertLogContains fails unless a sleep is introduced; possible race condition in waitForCompletion
}

@Issue("JENKINS-62014")
@Test public void envVarFilters() throws Exception {
EnvVarsFilterGlobalConfiguration.getAllActivatedGlobalRules().add(new RemoveSpecificVariablesFilter("FOO", "TODO: UNUSED"));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure the value parameter in the constructor for RemoveSpecificVariablesFilter is unused and could be removed. It's not used in config.jelly either from what I can see.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnvVarsFilterGlobalConfiguration.getAllActivatedGlobalRules().add(new VariableContributingFilter("BAZ", "QUX"));
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node() {\n" +
" withEnv(['FOO=BAR']) {\n" +
" sh('echo FOO=$FOO and BAZ=$BAZ')\n" +
" }\n" +
"}", true));
WorkflowRun b = j.buildAndAssertSuccess(p);
j.assertLogContains("FOO=", b);
j.assertLogNotContains("FOO=BAR", b);
j.assertLogContains("BAZ=QUX", b);
}

/**
* Asserts that the predicate remains true up to the given timeout.
*/
Expand Down