Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Nth build failure for Email Extension plugin #1297

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ExtendedEmailTriggerContext implements Context {
boolean attachBuildLog
boolean compressBuildLog
final List<String> replyToList = []
int failureCount = -1

/**
* Specifies the email recipients.
Expand Down Expand Up @@ -88,4 +89,11 @@ class ExtendedEmailTriggerContext implements Context {
void replyToList(String... replyToList) {
this.replyToList.addAll(replyToList)
}

/**
* Specifies the failure count to be applied to the xNthFailure use case.
*/
void failureCount(int failureCount) {
this.failureCount = failureCount
}
cml37 marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class ExtendedEmailTriggersContext implements Context {
addTrigger('SecondFailure', closure)
}

/**
* Triggers an email when the build fails n times in a row after a successful build
*/
void xNthFailure(@DslContext(ExtendedEmailTriggerContext) Closure closure = null) {
addTrigger('XNthFailure', closure)
}

/**
* Triggers an email any time the build fails.
*/
Expand Down Expand Up @@ -131,6 +138,9 @@ class ExtendedEmailTriggersContext implements Context {
ContextHelper.executeInContext(closure, context)

configuredTriggers << new NodeBuilder()."hudson.plugins.emailext.plugins.trigger.${name}Trigger" {
if (context.failureCount != -1) {
requiredFailureCount(context.failureCount)
}
email {
recipientList(context.recipientList.join(', '))
subject(context.subject ?: '')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class PublisherContextSpec extends Specification {
'firstUnstable' || 'FirstUnstableTrigger'
'stillUnstable' || 'StillUnstableTrigger'
'fixedUnhealthy' || 'FixedUnhealthyTrigger'
'xNthFailure' || 'XNthFailureTrigger'
}

def 'call standard mailer method'() {
Expand Down