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

[JENKINS-63254][JENKINS-47101] add watch variables to EnvironmentExpander #57

Merged
merged 5 commits into from
Oct 14, 2020
Merged
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
import hudson.model.Computer;
import hudson.model.Run;
import hudson.model.TaskListener;

import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

Expand All @@ -48,6 +52,15 @@ public abstract class EnvironmentExpander implements Serializable {
*/
public abstract void expand(@Nonnull EnvVars env) throws IOException, InterruptedException;

/**
* Override this method to allow tracking of sensitive environment variables
*
* @return the set of sensitive environment variable names to track.
*/
public Set<String> getSensitiveVars() {
return Collections.emptySet();
}
jglick marked this conversation as resolved.
Show resolved Hide resolved

/**
* Provides an expander for a constant map of string keys and string values. Supports {@link EnvVars#override(String, String)}
* behavior, such as {@code PATH+XYZ} overrides.
Expand Down Expand Up @@ -92,10 +105,25 @@ private static class MergedEnvironmentExpander extends EnvironmentExpander {
this.original = original;
this.subsequent = subsequent;
}

@Override public void expand(EnvVars env) throws IOException, InterruptedException {
original.expand(env);
subsequent.expand(env);
}

@Override
public Set<String> getSensitiveVars() {
Set<String> originalSensitive = original.getSensitiveVars();
Set<String> subsequentSensitive = subsequent.getSensitiveVars();
if (originalSensitive.isEmpty() && subsequentSensitive.isEmpty()) {
return Collections.emptySet();
} else {
Set<String> mergedWatch = new HashSet<>();
mergedWatch.addAll(originalSensitive);
mergedWatch.addAll(subsequentSensitive);
return mergedWatch;
}
}
}

/**
Expand Down Expand Up @@ -142,5 +170,4 @@ private static class MergedEnvironmentExpander extends EnvironmentExpander {
}
return env;
}

}