Skip to content

Commit

Permalink
fix: contributing variables was broken (refs #285)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Nov 27, 2023
1 parent 56e6284 commit 87206dc
Showing 1 changed file with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package org.jenkinsci.plugins.gwt;

import com.google.common.base.Charsets;
import hudson.EnvVars;
import hudson.Extension;
import hudson.model.EnvironmentContributor;
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import javax.annotation.Nonnull;

@Extension
public class GenericWebhookEnvironmentContributor extends EnvironmentContributor {
private static final String CONTRIBUTING_VARIABLES =
GenericWebhookEnvironmentContributor.class.getSimpleName();

@SuppressWarnings("unchecked")
@Override
Expand All @@ -24,28 +25,26 @@ public void buildEnvironmentFor(
final GenericCause cause = (GenericCause) r.getCause(GenericCause.class);
if (cause != null) {
final boolean shouldLog =
(cause.isPrintContributedVariables() || cause.isPrintPostContent())
&& !cause.isPostContentPrinted();
(cause.isPrintContributedVariables() || cause.isPrintPostContent()) && !cause.isPostContentPrinted();
if (shouldLog) {
cause.setPostContentPrinted(true);
if (cause.isPrintPostContent()) {
listener.getLogger().println(CONTRIBUTING_VARIABLES);
listener.getLogger().println(" Received:\n\n" + cause.getPostContent() + "\n\n");
}
final Map<String, String> resolvedVariables = cause.getResolvedVariables();
if (cause.isPrintContributedVariables()) {
listener.getLogger().println("Contributing variables:\n");
}
for (final String variable : resolvedVariables.keySet()) {
final String resolved = cause.getResolvedVariables().get(variable);
if (cause.isPrintContributedVariables()) {
listener.getLogger().println(" " + variable + " = " + resolved);
}
envs.override(variable, resolved);
}
if (cause.isPrintContributedVariables()) {
listener.getLogger().println("\n");
}
if (shouldLog && cause.isPrintPostContent()) {
listener.getLogger().println(" Received:\n\n" + cause.getPostContent() + "\n\n");
}
final Map<String, String> resolvedVariables = cause.getResolvedVariables();
if (shouldLog && cause.isPrintContributedVariables()) {
listener.getLogger().println("Contributing variables:\n");
}
for (final String variable : resolvedVariables.keySet()) {
final String resolved = cause.getResolvedVariables().get(variable);
if (shouldLog && cause.isPrintContributedVariables()) {
listener.getLogger().println(" " + variable + " = " + resolved);
}
envs.override(variable, resolved);
}
if (shouldLog && cause.isPrintContributedVariables()) {
listener.getLogger().println("\n");
}
}
}
Expand Down

0 comments on commit 87206dc

Please sign in to comment.