Skip to content

Commit

Permalink
add SUCCESS trigger option, modify conf
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderlz committed Sep 17, 2015
1 parent 58cd913 commit 7bfd146
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pager-duty</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.2-SNAPSHOT</version>
<packaging>hpi</packaging>

<name>PagerDuty Plugin</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
public class PagerDutyTrigger extends Notifier {

public final String apiKey;
public final boolean triggerOnSuccess;
public final String incidentKey;
public final String description;
private static PagerDuty pagerDuty;

@DataBoundConstructor
public PagerDutyTrigger(String apiKey, String incidentKey, String description) {
public PagerDutyTrigger(String apiKey, boolean triggerOnSuccess, String incidentKey, String description) {
this.apiKey = apiKey;
this.triggerOnSuccess = triggerOnSuccess;
this.incidentKey = incidentKey;
this.description = description;
pagerDuty = PagerDuty.create(apiKey);
Expand All @@ -56,9 +58,8 @@ public BuildStepMonitor getRequiredMonitorService() {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
BuildListener listener) throws InterruptedException, IOException {
if (build.getResult() == Result.SUCCESS)
return true;
else {
if ((build.getResult() == Result.SUCCESS && triggerOnSuccess) ||
(build.getResult() != Result.SUCCESS && !triggerOnSuccess)) {
listener.getLogger().println("Triggering PagerDuty Notification");
triggerPagerDuty(listener);
}
Expand All @@ -70,7 +71,8 @@ void triggerPagerDuty(BuildListener listener) {

try {
Trigger trigger;
if (incidentKey != null && incidentKey != "") {
listener.getLogger().printf("Triggering pagerDuty with incidentKey %s%n", incidentKey);
if (incidentKey != null && incidentKey.length() > 0) {
trigger = new Trigger.Builder(description).withIncidentKey(incidentKey).build();
} else {
trigger = new Trigger.Builder(description).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
<f:entry title="Api Key" field="apiKey">
<f:password field="apiKey" />
</f:entry>
<f:block>
<table>
<f:optionalBlock name="existingIncident" title="Use existing Incident Key">
<f:entry title="incidentKey" field="incidentKey">
<f:textbox field="incidentKey"/>
</f:entry>
</f:optionalBlock>
</table>
</f:block>
<f:entry title="incidentKey" field="incidentKey">
<f:textbox field="incidentKey"/>
</f:entry>
<f:entry title="Incident Description" field="description">
<f:textbox field="description"/>
<f:textbox field="description"/>
</f:entry>
<f:entry title="Trigger Incident on SUCCESS job result" field="triggerOnSuccess">
<f:checkbox name="triggerOnSuccess"/>
</f:entry>
</j:jelly>

0 comments on commit 7bfd146

Please sign in to comment.