-
-
Notifications
You must be signed in to change notification settings - Fork 107
JENKINS-61735 Get all environment variable #92
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
21ba9f3
cfd5a0b
27028f4
56056ae
393b0ac
454f85f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,14 +16,16 @@ | |
| public class LogstashConsoleLogFilter extends ConsoleLogFilter implements Serializable | ||
| { | ||
|
|
||
| private hudson.EnvVars envVars; | ||
| private static final Logger LOGGER = Logger.getLogger(LogstashConsoleLogFilter.class.getName()); | ||
|
|
||
| private transient Run<?, ?> run; | ||
| public LogstashConsoleLogFilter() {} | ||
|
|
||
| public LogstashConsoleLogFilter(Run<?, ?> run) | ||
| public LogstashConsoleLogFilter(Run<?, ?> run, hudson.EnvVars envVars) | ||
|
||
| { | ||
| this.run = run; | ||
| this.envVars = envVars; | ||
| } | ||
| private static final long serialVersionUID = 1L; | ||
|
|
||
|
|
@@ -62,7 +64,7 @@ public OutputStream decorateLogger(Run build, OutputStream logger) throws IOExce | |
|
|
||
| LogstashWriter getLogStashWriter(Run<?, ?> build, OutputStream errorStream) | ||
| { | ||
| return new LogstashWriter(build, errorStream, null, build.getCharset()); | ||
| return new LogstashWriter(build, errorStream, null, build.getCharset(), envVars); | ||
| } | ||
|
|
||
| private boolean isLogstashEnabled(Run<?, ?> build) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,7 +107,7 @@ private boolean perform(Run<?, ?> run, TaskListener listener) { | |
|
|
||
| // Method to encapsulate calls for unit-testing | ||
| LogstashWriter getLogStashWriter(Run<?, ?> run, OutputStream errorStream, TaskListener listener) { | ||
| return new LogstashWriter(run, errorStream, listener, run.getCharset()); | ||
| return new LogstashWriter(run, errorStream, listener, run.getCharset(), null); | ||
|
||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,21 +212,14 @@ public BuildData(AbstractBuild<?, ?> build, Date currentTime, TaskListener liste | |
| } | ||
|
|
||
| // Pipeline project build | ||
| public BuildData(Run<?, ?> build, Date currentTime, TaskListener listener) { | ||
| public BuildData(Run<?, ?> build, Date currentTime, TaskListener listener, hudson.EnvVars envVars) { | ||
| initData(build, currentTime); | ||
|
|
||
| buildVariables = envVars; | ||
| rootProjectName = projectName; | ||
| rootFullProjectName = fullProjectName; | ||
| rootProjectDisplayName = displayName; | ||
| rootBuildNum = buildNum; | ||
|
|
||
| try { | ||
| // TODO: sensitive variables are not filtered, c.f. https://stackoverflow.com/questions/30916085 | ||
| buildVariables = build.getEnvironment(listener); | ||
| } catch (IOException | InterruptedException e) { | ||
| LOGGER.log(WARNING,"Unable to get environment for " + build.getDisplayName(),e); | ||
| buildVariables = new HashMap<>(); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is wrong to remove this block. For non pipeline builds this would result in a loss of information. So in case the buildVariables is null it should be filled as done before.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't catch. I thought that this part of code (line 215. public BuildData(Run build, Date currentTime, TaskListener listener, hudson.EnvVars envVars) {) was on "ly for declarative pipeline and not for non pipeline builds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think best way to resolve this would be to add some automated tests to show it's working
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Concerning sensitive info, you are probably right, but that need to be checked. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filtering for sensitive variables is not supported in Pipeline. At least it wasn't last time I checked. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This constructor is indeed not called for instances of AbstractBuild. But it is not limited to WorkflowRun. It will also be called for any other implementation directly inheriting from Run (e.g. AsyncRun, ExternalRun, see https://jenkins.io/doc/developer/extensions/jenkins-core/#run)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. I suggest to keep this code but to execute it only if enVars is non null or empty if I figure out to create a new contructor (I guess it's related with your comment src/main/java/jenkins/plugins/logstash/LogstashNotifier.java line 110). |
||
| } | ||
|
|
||
| private void initData(Run<?, ?> build, Date currentTime) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,7 @@ public boolean start() throws Exception { | |
| context | ||
| .newBodyInvoker() | ||
| .withContext(createConsoleLogFilter(context)) | ||
| .withContext(context.get(hudson.EnvVars.class)) | ||
| .withCallback(BodyExecutionCallback.wrap(context)) | ||
| .start(); | ||
| return false; | ||
|
|
@@ -68,7 +69,8 @@ private ConsoleLogFilter createConsoleLogFilter(StepContext context) | |
| throws IOException, InterruptedException { | ||
| ConsoleLogFilter original = context.get(ConsoleLogFilter.class); | ||
| Run<?, ?> build = context.get(Run.class); | ||
| ConsoleLogFilter subsequent = new LogstashConsoleLogFilter(build); | ||
| hudson.EnvVars envVars = context.get(hudson.EnvVars.class); | ||
|
||
| ConsoleLogFilter subsequent = new LogstashConsoleLogFilter(build, envVars); | ||
| return BodyInvoker.mergeConsoleLogFilters(original, subsequent); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change to using imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK