Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new trigger BuildingTrigger that is triggered on the transition from Failure to Unstable.
- Loading branch information
Showing
6 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/main/java/hudson/plugins/emailext/plugins/trigger/BuildingTrigger.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,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; | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
src/test/java/hudson/plugins/emailext/plugins/trigger/BuildingTriggerTest.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,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); | ||
} | ||
} |
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
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
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