Skip to content

Commit

Permalink
Custom cause #57
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Apr 18, 2018
1 parent 26d2865 commit 1f00067
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
18 changes: 13 additions & 5 deletions src/main/java/org/jenkinsci/plugins/gwt/GenericCause.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.gwt;

import static com.google.common.base.Strings.isNullOrEmpty;
import hudson.model.Cause;

import java.util.Map;
Expand All @@ -10,16 +11,23 @@ public class GenericCause extends Cause {
private final String postContent;
private final boolean printContributedVariables;
private final boolean printPostContent;
private final String cause;

public GenericCause(
String postContent,
Map<String, String> resolvedVariables,
boolean printContributedVariables,
boolean printPostContent) {
final String postContent,
final Map<String, String> resolvedVariables,
final boolean printContributedVariables,
final boolean printPostContent,
final String cause) {
this.postContent = postContent;
this.resolvedVariables = resolvedVariables;
this.printContributedVariables = printContributedVariables;
this.printPostContent = printPostContent;
if (!isNullOrEmpty(cause)) {
this.cause = cause;
} else {
this.cause = "Generic Cause";
}
}

public boolean isPrintContributedVariables() {
Expand All @@ -40,6 +48,6 @@ public String getPostContent() {

@Override
public String getShortDescription() {
return "Generic Cause";
return cause;
}
}
17 changes: 14 additions & 3 deletions src/main/java/org/jenkinsci/plugins/gwt/GenericTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class GenericTrigger extends Trigger<Job<?, ?>> {
private List<GenericHeaderVariable> genericHeaderVariables = newArrayList();
private boolean printPostContent;
private boolean printContributedVariables;
private String causeString;

public static class GenericDescriptor extends TriggerDescriptor {

Expand Down Expand Up @@ -71,6 +72,15 @@ public GenericTrigger(
this.genericHeaderVariables = genericHeaderVariables;
}

@DataBoundSetter
public void setCauseString(final String causeString) {
this.causeString = causeString;
}

public String getCauseString() {
return causeString;
}

@DataBoundSetter
public void setPrintContributedVariables(final boolean printContributedVariables) {
this.printContributedVariables = printContributedVariables;
Expand Down Expand Up @@ -111,14 +121,15 @@ public GenericTriggerResults trigger(

hudson.model.Queue.Item item = null;
if (isMatching) {
final GenericCause cause =
final String cause = renderText(causeString, resolvedVariables);
final GenericCause genericCause =
new GenericCause(
postContent, resolvedVariables, printContributedVariables, printPostContent);
postContent, resolvedVariables, printContributedVariables, printPostContent, cause);

final ParametersAction parameters = createParameters(job, resolvedVariables);
item =
retrieveScheduleJob(job) //
.scheduleBuild2(job, 0, new CauseAction(cause), parameters);
.scheduleBuild2(job, 0, new CauseAction(genericCause), parameters);
}
return new GenericTriggerResults(
item, resolvedVariables, renderedRegexpFilterText, regexpFilterExpression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
</f:description>
</f:entry>

<f:entry title="Cause">
<f:textbox field="causeString" default="Generic Cause"/>
<f:description>
This will be displayed in any triggered job. You can use the variables here to create a custom cause like <i>"$name committed to $branch"</i>, if you have configured variables named <b>name</b> and <b>branch</b>.
</f:description>
</f:entry>

<f:entry title="Print post content" field="printPostContent">
<f:checkbox/>
Expand Down

0 comments on commit 1f00067

Please sign in to comment.