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
Merge pull request #139 from KostyaSha/Xtrigger
[Fix JENKINS-37995] X failure trigger
- Loading branch information
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/hudson/plugins/emailext/plugins/trigger/XNthFailureTrigger.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,49 @@ | ||
package hudson.plugins.emailext.plugins.trigger; | ||
|
||
import hudson.Extension; | ||
import hudson.plugins.emailext.plugins.EmailTrigger; | ||
import hudson.plugins.emailext.plugins.RecipientProvider; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Kanstantsin Shautsou | ||
*/ | ||
public class XNthFailureTrigger extends NthFailureTrigger { | ||
public static final String TRIGGER_NAME = "Failure - X"; | ||
|
||
private int requiredFailureCount = 3; | ||
|
||
@DataBoundConstructor | ||
public XNthFailureTrigger(List<RecipientProvider> recipientProviders, String recipientList, String replyTo, | ||
String subject, String body, String attachmentsPattern, int attachBuildLog, | ||
String contentType) { | ||
super(recipientProviders, recipientList, replyTo, subject, body, attachmentsPattern, attachBuildLog, contentType); | ||
} | ||
|
||
@Override | ||
protected int getRequiredFailureCount() { | ||
return requiredFailureCount; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setRequiredFailureCount(int requiredFailureCount) { | ||
this.requiredFailureCount = requiredFailureCount; | ||
} | ||
|
||
@Extension | ||
public static final class DescriptorImpl extends NthFailureTrigger.DescriptorImpl { | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return TRIGGER_NAME; | ||
} | ||
|
||
@Override | ||
public EmailTrigger createDefault() { | ||
return _createDefault(); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/resources/hudson/plugins/emailext/plugins/trigger/XNthFailureTrigger/help.html
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,3 @@ | ||
<div> | ||
An email will be sent when the build fails X times in a row after a successful build. | ||
</div> |
7 changes: 7 additions & 0 deletions
7
.../resources/hudson/plugins/emailext/plugins/trigger/XNthFailureTrigger/local-config.groovy
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,7 @@ | ||
package hudson.plugins.emailext.plugins.trigger.XNthFailureTrigger | ||
|
||
f = namespace("/lib/form") | ||
|
||
f.entry(title: _("Number Of Failures")) { | ||
f.number(name: "requiredFailureCount") | ||
} |
54 changes: 54 additions & 0 deletions
54
src/test/java/hudson/plugins/emailext/plugins/trigger/XNthFailureTriggerTest.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,54 @@ | ||
package hudson.plugins.emailext.plugins.trigger; | ||
|
||
import hudson.model.Result; | ||
import hudson.plugins.emailext.plugins.EmailTrigger; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static hudson.model.Result.FAILURE; | ||
import static hudson.model.Result.SUCCESS; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* @author Kanstantsin Shautsou | ||
*/ | ||
public class XNthFailureTriggerTest extends TriggerTestBase { | ||
@Override | ||
EmailTrigger newInstance() { | ||
XNthFailureTrigger trigger = new XNthFailureTrigger(recProviders, "", "", "", "", "", 0, "project"); | ||
trigger.setRequiredFailureCount(3); | ||
return trigger; | ||
} | ||
|
||
@Test | ||
public void testTrigger_success() | ||
throws IOException, InterruptedException { | ||
assertNotTriggered(SUCCESS); | ||
assertNotTriggered(SUCCESS, SUCCESS); | ||
assertNotTriggered(SUCCESS, SUCCESS, SUCCESS); | ||
assertNotTriggered(SUCCESS, SUCCESS, SUCCESS, SUCCESS); | ||
} | ||
|
||
@Test | ||
public void testTrigger_thirdFailureAfterSuccess() | ||
throws IOException, InterruptedException { | ||
assertTriggered(FAILURE, SUCCESS, FAILURE, FAILURE, FAILURE); | ||
} | ||
|
||
@Test | ||
public void testTrigger_thirdBuildFails() | ||
throws IOException, InterruptedException { | ||
assertTriggered(FAILURE, FAILURE, FAILURE); | ||
assertTriggered(SUCCESS, FAILURE, FAILURE, FAILURE); | ||
} | ||
|
||
@Test | ||
public void testTrigger_failure() | ||
throws IOException, InterruptedException { | ||
assertNotTriggered(FAILURE); | ||
assertNotTriggered(FAILURE, FAILURE); | ||
assertNotTriggered(SUCCESS, FAILURE, FAILURE); | ||
assertNotTriggered(SUCCESS, FAILURE, FAILURE, SUCCESS); | ||
} | ||
} |