Skip to content
Permalink
Browse files
Fixed JENKINS-17546
Added new trigger BuildingTrigger that is triggered on the transition
from Failure to Unstable.
  • Loading branch information
slide committed Apr 19, 2013
1 parent 7cabc47 commit 3ea1848751f762f26674c7a8d92023bbe59d4117
Showing 6 changed files with 129 additions and 3 deletions.
@@ -0,0 +1,67 @@
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;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;

public class BuildingTrigger extends EmailTrigger {

public static final String TRIGGER_NAME = "Building";

@Override
public boolean trigger(AbstractBuild<?, ?> build) {

Result buildResult = build.getResult();

if (buildResult == Result.UNSTABLE) {
AbstractBuild<?, ?> prevBuild = build.getPreviousBuild();
if (prevBuild != null && (prevBuild.getResult() == Result.FAILURE)) {
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() {

}

@Override
public String getTriggerName() {
return TRIGGER_NAME;
}

@Override
public EmailTrigger newInstance(StaplerRequest req, JSONObject formData) {
return new FixedTrigger();
}

@Override
public String getHelpText() {
return Messages.BuildingTrigger_HelpText();
}
}

@Override
public boolean getDefaultSendToDevs() {
return true;
}

@Override
public boolean getDefaultSendToList() {
return true;
}
}
@@ -34,3 +34,6 @@ ScriptTrigger.HelpText=\
PreBuildScriptTrigger.HelpText=\
Allows the user to define a script which must have the last line resolve to a true or false which will\
indicate whether the trigger should cause an email to be sent BEFORE build or not.
BuildingTrigger.HelpText=\
An email will be sent any time the build goes from failing, to unstable. This basically means that\
all the builds steps were successful, but there are still tests failing.
@@ -0,0 +1,56 @@
package hudson.plugins.emailext.plugins.trigger;

import hudson.model.Result;
import hudson.plugins.emailext.plugins.EmailTrigger;

import java.io.IOException;

import org.junit.Test;

/**
*
* @author acearl
*/
public class BuildingTriggerTest extends TriggerTestBase {

@Override
EmailTrigger newInstance() {
return new BuildingTrigger();
}

@Test
public void testTrigger_success()
throws IOException, InterruptedException {
assertNotTriggered(Result.SUCCESS);
}

@Test
public void testTrigger_failure()
throws IOException, InterruptedException {
assertNotTriggered(Result.SUCCESS);
}

@Test
public void testTrigger_failureUnstable()
throws IOException, InterruptedException {
assertTriggered(Result.FAILURE, Result.UNSTABLE);
}

@Test
public void testTrigger_multipleFailure()
throws IOException, InterruptedException {
assertTriggered(Result.FAILURE, Result.FAILURE, Result.FAILURE, Result.UNSTABLE);
}

@Test
public void testTrigger_failureSuccess()
throws IOException, InterruptedException {
assertNotTriggered(Result.FAILURE, Result.SUCCESS);
}

@Test
public void testTrigger_failureSuccessUnstable()
throws IOException, InterruptedException {
assertNotTriggered(Result.FAILURE, Result.SUCCESS, Result.UNSTABLE);
}
}
@@ -10,7 +10,7 @@
import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class FirstFailureTriggerTest extends NthFailureTriggerTestBase {
public class FirstFailureTriggerTest extends TriggerTestBase {

@Override
EmailTrigger newInstance() {
@@ -7,7 +7,7 @@

import org.junit.Test;

public class SecondFailureTriggerTest extends NthFailureTriggerTestBase {
public class SecondFailureTriggerTest extends TriggerTestBase {

@Override
EmailTrigger newInstance() {
@@ -15,7 +15,7 @@
/**
* Base class for testing
*/
public abstract class NthFailureTriggerTestBase {
public abstract class TriggerTestBase {

abstract EmailTrigger newInstance();

0 comments on commit 3ea1848

Please sign in to comment.