Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix JENKINS-7859
- Added FirstFailureTrigger.java to handle the case when a build moves from Success to Failure (or on first build run + Failure)
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/hudson/plugins/emailext/plugins/trigger/FirstFailureTrigger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package hudson.plugins.emailext.plugins.trigger; | ||
|
||
import hudson.model.AbstractBuild; | ||
import hudson.model.Result; | ||
import hudson.plugins.emailext.plugins.EmailTrigger; | ||
import hudson.plugins.emailext.plugins.EmailTriggerDescriptor; | ||
|
||
public class FirstFailureTrigger extends EmailTrigger { | ||
|
||
public static final String TRIGGER_NAME = "First Failure"; | ||
|
||
@Override | ||
public boolean trigger(AbstractBuild<?,?> build) { | ||
|
||
Result buildResult = build.getResult(); | ||
|
||
if (buildResult == Result.FAILURE) { | ||
AbstractBuild<?,?> prevBuild = build.getPreviousBuild(); | ||
// if there is no previous build, this is a first failure | ||
// if there is a previous build and it's result was success, this is first failure | ||
if (prevBuild == null || (prevBuild.getResult() == Result.SUCCESS)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public EmailTriggerDescriptor getDescriptor() { | ||
return DESCRIPTOR; | ||
} | ||
|
||
public static DescriptorImpl DESCRIPTOR = new DescriptorImpl(); | ||
|
||
public static final class DescriptorImpl extends EmailTriggerDescriptor { | ||
|
||
public DescriptorImpl() { | ||
addTriggerNameToReplace(SuccessTrigger.TRIGGER_NAME); | ||
} | ||
|
||
@Override | ||
public String getTriggerName() { | ||
return TRIGGER_NAME; | ||
} | ||
|
||
@Override | ||
public EmailTrigger newInstance() { | ||
return new FirstFailureTrigger(); | ||
} | ||
|
||
@Override | ||
public String getHelpText() { | ||
return "An email will be sent when the build status changes from \"Success\" " + | ||
"to \"Failure\""; | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public boolean getDefaultSendToDevs() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean getDefaultSendToList() { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters