Skip to content
Permalink
Browse files
JENKINS-37188 2nd failure emails being sent even when build is succes…
…sful with job-dsl-plugin
  • Loading branch information
davidvanlaatum committed Aug 7, 2016
1 parent 363a6e6 commit f75318d75a5129a0d91773906962efc24337fdcf
@@ -13,14 +13,19 @@ public class FirstFailureTrigger extends NthFailureTrigger {

@DataBoundConstructor
public FirstFailureTrigger(List<RecipientProvider> recipientProviders, String recipientList, String replyTo, String subject, String body, String attachmentsPattern, int attachBuildLog, String contentType) {
super(1, recipientProviders, recipientList, replyTo, subject, body, attachmentsPattern, attachBuildLog, contentType);
super(recipientProviders, recipientList, replyTo, subject, body, attachmentsPattern, attachBuildLog, contentType);
}

@Deprecated
public FirstFailureTrigger(boolean sendToList, boolean sendToDevs, boolean sendToRequester, boolean sendToCulprits, String recipientList, String replyTo, String subject, String body, String attachmentsPattern, int attachBuildLog, String contentType) {
super(1, sendToList, sendToDevs, sendToRequester, sendToCulprits,recipientList, replyTo, subject, body, attachmentsPattern, attachBuildLog, contentType);
}

@Override
protected int getRequiredFailureCount() {
return 1;
}

@Extension
public static final class DescriptorImpl extends NthFailureTrigger.DescriptorImpl {

@@ -33,16 +38,4 @@ public EmailTrigger createDefault() {
return _createDefault();
}
}

/**
* Maintaining backward compatibility
*
* @return this after checking for failureCount setting
*/
public Object readResolve() {
if (this.failureCount == 0) {
this.failureCount = 1;
}
return this;
}
}
@@ -18,24 +18,37 @@
*/
public abstract class NthFailureTrigger extends EmailTrigger {

@Deprecated
protected int failureCount;


/** @deprecated override getRequiredFailureCount instead of passing in failureCount */
@Deprecated
public NthFailureTrigger(int failureCount, 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);
this.failureCount = failureCount;
}

public NthFailureTrigger(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);
}

@Deprecated
public NthFailureTrigger(int failureCount, boolean sendToList, boolean sendToDevs, boolean sendToRequester, boolean sendToCulprits, String recipientList, String replyTo, String subject, String body, String attachmentsPattern, int attachBuildLog, String contentType) {
super(sendToList, sendToDevs, sendToRequester, sendToCulprits,recipientList, replyTo, subject, body, attachmentsPattern, attachBuildLog, contentType);
this.failureCount = failureCount;
}

@SuppressWarnings("deprecation")
protected int getRequiredFailureCount() {
return failureCount;
}

@Override
public boolean trigger(AbstractBuild<?, ?> build, TaskListener listener) {
Run<?,?> run = build;
int count = getRequiredFailureCount();
// Work back through the failed builds.
for (int i = 0; i < failureCount; i++) {
for (int i = 0; i < count; i++) {
if (run == null) {
// We don't have enough history to have reached the failure count.
return false;
@@ -12,14 +12,19 @@ public class SecondFailureTrigger extends NthFailureTrigger {

@DataBoundConstructor
public SecondFailureTrigger(List<RecipientProvider> recipientProviders, String recipientList, String replyTo, String subject, String body, String attachmentsPattern, int attachBuildLog, String contentType) {
super(2, recipientProviders, recipientList, replyTo, subject, body, attachmentsPattern, attachBuildLog, contentType);
super(recipientProviders, recipientList, replyTo, subject, body, attachmentsPattern, attachBuildLog, contentType);
}

@Deprecated
public SecondFailureTrigger(boolean sendToList, boolean sendToDevs, boolean sendToRequester, boolean sendToCulprits, String recipientList, String replyTo, String subject, String body, String attachmentsPattern, int attachBuildLog, String contentType) {
super(2, sendToList, sendToDevs, sendToRequester, sendToCulprits,recipientList, replyTo, subject, body, attachmentsPattern, attachBuildLog, contentType);
}

@Override
protected int getRequiredFailureCount() {
return 2;
}

@Extension
public static final class DescriptorImpl extends NthFailureTrigger.DescriptorImpl {

@@ -53,14 +53,4 @@ public void testTrigger_firstTwoBuildsFail()
throws IOException, InterruptedException {
assertNotTriggered(Result.FAILURE, Result.FAILURE);
}

@Test
public void testUpgrade()
throws IOException, InterruptedException {

XStream2 xs = new XStream2();
InputStream is = FirstFailureTriggerTest.class.getResourceAsStream("oldformat.xml");
FirstFailureTrigger t = (FirstFailureTrigger) xs.fromXML(is);
assertEquals(t.failureCount, 1);
}
}

This file was deleted.

0 comments on commit f75318d

Please sign in to comment.