Skip to content
Permalink
Browse files
Merge pull request #19 from oldelvet/jenkins-10990
[FIXED JENKINS-10990] Send email for NOT_BUILT and ABORTED builds.
  • Loading branch information
slide committed Sep 13, 2011
2 parents c7f4c46 + 6d206a3 commit c0ba908117469a938473d74b10de25c144c26525
@@ -28,8 +28,10 @@
import hudson.plugins.emailext.plugins.EmailContent;
import hudson.plugins.emailext.plugins.EmailTriggerDescriptor;
import hudson.plugins.emailext.plugins.content.*;
import hudson.plugins.emailext.plugins.trigger.AbortedTrigger;
import hudson.plugins.emailext.plugins.trigger.FailureTrigger;
import hudson.plugins.emailext.plugins.trigger.FixedTrigger;
import hudson.plugins.emailext.plugins.trigger.NotBuiltTrigger;
import hudson.plugins.emailext.plugins.trigger.PreBuildTrigger;
import hudson.plugins.emailext.plugins.trigger.StillFailingTrigger;
import hudson.plugins.emailext.plugins.trigger.StillUnstableTrigger;
@@ -82,6 +84,8 @@ public void start() throws Exception {
addEmailTriggerPlugin(StillUnstableTrigger.DESCRIPTOR);
addEmailTriggerPlugin(SuccessTrigger.DESCRIPTOR);
addEmailTriggerPlugin(FixedTrigger.DESCRIPTOR);
addEmailTriggerPlugin(AbortedTrigger.DESCRIPTOR);
addEmailTriggerPlugin(NotBuiltTrigger.DESCRIPTOR);
}

private void addEmailContentPlugin(EmailContent content) {
@@ -79,6 +79,10 @@ public <P extends AbstractProject<P, B>, B extends AbstractBuild<P, B>> String g
} else {
return "Successful";
}
} else if (buildResult == Result.NOT_BUILT) {
return "Not Built";
} else if (buildResult == Result.ABORTED) {
return "Aborted";
}

return "Unknown";
@@ -0,0 +1,60 @@
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;

public class AbortedTrigger extends EmailTrigger {

public static final String TRIGGER_NAME = "Aborted";

public AbortedTrigger() {
}

@Override
public boolean trigger(AbstractBuild<?, ?> build) {
Result buildResult = build.getResult();

if (buildResult == Result.ABORTED) {
return true;
}

return false;
}

@Override
public EmailTriggerDescriptor getDescriptor() {
return DESCRIPTOR;
}

public static DescriptorImpl DESCRIPTOR = new DescriptorImpl();

public static final class DescriptorImpl extends EmailTriggerDescriptor {

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

@Override
public EmailTrigger newInstance() {
return new AbortedTrigger();
}

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

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

@Override
public boolean getDefaultSendToList() {
return true;
}
}
@@ -0,0 +1,60 @@
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;

public class NotBuiltTrigger extends EmailTrigger {

public static final String TRIGGER_NAME = "Not Built";

public NotBuiltTrigger() {
}

@Override
public boolean trigger(AbstractBuild<?, ?> build) {
Result buildResult = build.getResult();

if (buildResult == Result.NOT_BUILT) {
return true;
}

return false;
}

@Override
public EmailTriggerDescriptor getDescriptor() {
return DESCRIPTOR;
}

public static DescriptorImpl DESCRIPTOR = new DescriptorImpl();

public static final class DescriptorImpl extends EmailTriggerDescriptor {

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

@Override
public EmailTrigger newInstance() {
return new NotBuiltTrigger();
}

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

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

@Override
public boolean getDefaultSendToList() {
return true;
}
}
@@ -16,4 +16,8 @@ SuccessTrigger.HelpText=\
UnstableTrigger.HelpText=\
An email will be sent any time the build is unstable.\
If the "Still Unstable" trigger is configured, and the previous build status was "Unstable",\
then the "Still Unstable" trigger will send an email instead.
then the "Still Unstable" trigger will send an email instead.
NotBuiltTrigger.HelpText=\
An email will be sent if the build status is "Not Built".
AbortedTrigger.HelpText=\
An email will be sent if the build status is "Aborted".
@@ -6,15 +6,18 @@
import hudson.model.Result;
import hudson.model.User;
import hudson.plugins.emailext.plugins.EmailTrigger;
import hudson.plugins.emailext.plugins.trigger.AbortedTrigger;
import hudson.plugins.emailext.plugins.trigger.FailureTrigger;
import hudson.plugins.emailext.plugins.trigger.FixedTrigger;
import hudson.plugins.emailext.plugins.trigger.NotBuiltTrigger;
import hudson.plugins.emailext.plugins.trigger.PreBuildTrigger;
import hudson.plugins.emailext.plugins.trigger.StillFailingTrigger;
import hudson.plugins.emailext.plugins.trigger.SuccessTrigger;
import hudson.tasks.Mailer;
import net.sf.json.JSONObject;
import org.jvnet.hudson.test.FailureBuilder;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.MockBuilder;
import org.jvnet.mock_javamail.Mailbox;

import java.util.List;
@@ -231,6 +234,75 @@ public void testStillFailingTriggerShouldSendEmailWhenBuildContinuesToFail()
Mailbox.get( "ashlux@gmail.com" ).size() );
}

public void testAbortedTriggerShouldSendEmailWhenBuildAborts()
throws Exception
{
project.getBuildersList().add( new MockBuilder(Result.ABORTED) );

AbortedTrigger abortedTrigger = new AbortedTrigger();
addEmailType( abortedTrigger );
publisher.getConfiguredTriggers().add( abortedTrigger );

FreeStyleBuild build = project.scheduleBuild2( 0 ).get();
assertBuildStatus( Result.ABORTED, build );

assertThat( "Email should have been triggered, so we should see it in the logs.", build.getLog( 100 ),
hasItems( "Email was triggered for: " + AbortedTrigger.TRIGGER_NAME ) );
assertEquals( 1, Mailbox.get( "ashlux@gmail.com" ).size() );
}

public void testAbortedTriggerShouldNotSendEmailWhenBuildFails()
throws Exception
{
project.getBuildersList().add( new FailureBuilder() );

AbortedTrigger trigger = new AbortedTrigger();
addEmailType( trigger );
publisher.getConfiguredTriggers().add( trigger );

FreeStyleBuild build = project.scheduleBuild2( 0 ).get();
assertBuildStatus( Result.FAILURE, build );

assertThat( "Email should not have been triggered, so we shouldn't see it in the logs.", build.getLog( 100 ),
not( hasItems( "Email was triggered for: " + AbortedTrigger.TRIGGER_NAME ) ) );
assertEquals( 0, Mailbox.get( "ashlux@gmail.com" ).size() );
}


public void testNotBuiltTriggerShouldSendEmailWhenNotBuilt()
throws Exception
{
project.getBuildersList().add( new MockBuilder(Result.NOT_BUILT) );

NotBuiltTrigger notbuiltTrigger = new NotBuiltTrigger();
addEmailType( notbuiltTrigger );
publisher.getConfiguredTriggers().add( notbuiltTrigger );

FreeStyleBuild build = project.scheduleBuild2( 0 ).get();
assertBuildStatus( Result.NOT_BUILT, build );

assertThat( "Email should have been triggered, so we should see it in the logs.", build.getLog( 100 ),
hasItems( "Email was triggered for: " + NotBuiltTrigger.TRIGGER_NAME ) );
assertEquals( 1, Mailbox.get( "ashlux@gmail.com" ).size() );
}

public void testNotBuiltTriggerShouldNotSendEmailWhenBuildFails()
throws Exception
{
project.getBuildersList().add( new FailureBuilder() );

NotBuiltTrigger trigger = new NotBuiltTrigger();
addEmailType( trigger );
publisher.getConfiguredTriggers().add( trigger );

FreeStyleBuild build = project.scheduleBuild2( 0 ).get();
assertBuildStatus( Result.FAILURE, build );

assertThat( "Email should not have been triggered, so we shouldn't see it in the logs.", build.getLog( 100 ),
not( hasItems( "Email was triggered for: " + NotBuiltTrigger.TRIGGER_NAME ) ) );
assertEquals( 0, Mailbox.get( "ashlux@gmail.com" ).size() );
}

public void testShouldSendEmailUsingUtf8ByDefault()
throws Exception
{

0 comments on commit c0ba908

Please sign in to comment.