Skip to content

Commit

Permalink
Only printing variables/post content once in the job log
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Apr 10, 2017
1 parent edbf392 commit 00bf4c7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Generic Webhook Plugin Changelog
Changelog of Generic Webhook Plugin.
## Unreleased
## 1.7
### No issue
**Correcting invoke URL in docs**

[417e712357349ff](https://github.com/jenkinsci/generic-webhook-trigger-plugin/commit/417e712357349ff) Tomas Bjerre *2017-04-07 18:27:58*

**doc**

[fd938b99aa7a609](https://github.com/jenkinsci/generic-webhook-trigger-plugin/commit/fd938b99aa7a609) Tomas Bjerre *2017-03-30 19:34:23*
[7ca0ca4e98a6747](https://github.com/jenkinsci/generic-webhook-trigger-plugin/commit/7ca0ca4e98a6747) Tomas Bjerre *2017-04-05 16:59:50*

## 1.6
### GitHub [#3](https://github.com/jenkinsci/generic-webhook-trigger-plugin/issues/3) Lacks job selection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jenkinsci.plugins.gwt;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Map;

Expand All @@ -13,27 +15,50 @@

@Extension
public class GenericWebhookEnvironmentContributor extends EnvironmentContributor {
private static final String CONTRIBUTING_VARIABLES = "Contributing variables:";

@Override
public void buildEnvironmentFor(
@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener)
throws IOException, InterruptedException {
boolean shouldLog = shouldLog(r);
GenericCause cause = (GenericCause) r.getCause(GenericCause.class);
if (cause != null) {
listener
.getLogger()
.println(
GenericWebhookEnvironmentContributor.class.getSimpleName()
+ " Received:\n\n"
+ cause.getPostContent()
+ "\n\n");
if (shouldLog) {
listener
.getLogger()
.println(
GenericWebhookEnvironmentContributor.class.getSimpleName()
+ " Received:\n\n"
+ cause.getPostContent()
+ "\n\n");
}
Map<String, String> resolvedVariables = cause.getResolvedVariables();
listener.getLogger().println("Contributing variables:\n");
if (shouldLog) {
listener.getLogger().println(CONTRIBUTING_VARIABLES + "\n");
}
for (String variable : resolvedVariables.keySet()) {
String resolved = cause.getResolvedVariables().get(variable);
listener.getLogger().println(" " + variable + " = " + resolved);
if (shouldLog) {
listener.getLogger().println(" " + variable + " = " + resolved);
}
envs.override(variable, resolved);
}
listener.getLogger().println("\n");
if (shouldLog) {
listener.getLogger().println("\n");
}
}
}

private boolean shouldLog(Run r) throws IOException {
try (BufferedReader br = new BufferedReader(new FileReader(r.getLogFile()))) {
String line;
while ((line = br.readLine()) != null) {
if (line.contains(CONTRIBUTING_VARIABLES)) {
return false;
}
}
}
return true;
}
}

0 comments on commit 00bf4c7

Please sign in to comment.