diff --git a/changelog.html b/changelog.html index 0bc014585f..834f40f26d 100644 --- a/changelog.html +++ b/changelog.html @@ -77,6 +77,9 @@ Upcoming changes (issue 11204)
  • Update center UI improvement. "Install" button is now always visisble. +
  • + Add option to disable mailnotification for each failed maven module. + (issue 5695)
  • Fixed a bug where a large output from Maven can cause module log output to go out of sync with module build log files.
  • diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java index 4f635d84aa..91151adb99 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java @@ -185,6 +185,14 @@ public class MavenModuleSet extends AbstractMavenProjecttrue to simulate old behavior. + *

    + * see JENKINS-5695. + */ + private Boolean perModuleEmail = Boolean.TRUE; /** * If true, do not automatically schedule a build when one of the project dependencies is built. @@ -436,6 +444,10 @@ public class MavenModuleSet extends AbstractMavenProject + + If checked, Jenkins will send an e-mail notifications for each module (e.g. failed, unstable). + \ No newline at end of file diff --git a/test/src/test/java/hudson/maven/reporters/MavenMailerTest.java b/test/src/test/java/hudson/maven/reporters/MavenMailerTest.java new file mode 100644 index 0000000000..e41dd37f78 --- /dev/null +++ b/test/src/test/java/hudson/maven/reporters/MavenMailerTest.java @@ -0,0 +1,67 @@ +package hudson.maven.reporters; + +import hudson.maven.MavenModuleSet; +import hudson.model.Result; +import hudson.tasks.Mailer; +import hudson.tasks.Mailer.DescriptorImpl; + +import javax.mail.Address; +import javax.mail.internet.InternetAddress; + +import jenkins.model.Jenkins; + +import org.jvnet.hudson.test.Bug; +import org.jvnet.hudson.test.ExtractResourceSCM; +import org.jvnet.hudson.test.HudsonTestCase; +import org.jvnet.mock_javamail.Mailbox; + +public class MavenMailerTest extends HudsonTestCase { + + @Bug(5695) + public void testMulipleMails() throws Exception { + + final Mailbox inbox = runMailTest(true); + assertEquals(2, inbox.size()); + + } + + @Bug(5695) + public void testSingleMails() throws Exception { + + final Mailbox inbox = runMailTest(false); + assertEquals(1, inbox.size()); + + } + + public Mailbox runMailTest(boolean perModuleEamil) throws Exception { + + final DescriptorImpl mailDesc = Jenkins.getInstance().getDescriptorByType(Mailer.DescriptorImpl.class); + + // intentionally give the whole thin in a double quote + Mailer.descriptor().setAdminAddress("\"me \""); + + String recipient = "you "; + Mailbox yourInbox = Mailbox.get(new InternetAddress(recipient)); + yourInbox.clear(); + + configureDefaultMaven(); + MavenModuleSet mms = createMavenProject(); + mms.setGoals("test"); + mms.setScm(new ExtractResourceSCM(getClass().getResource("/hudson/maven/maven-multimodule-unit-failure.zip"))); + assertBuildStatus(Result.UNSTABLE, mms.scheduleBuild2(0).get()); + + MavenMailer m = new MavenMailer(); + m.recipients = recipient; + m.perModuleEmail = perModuleEamil; + mms.getReporters().add(m); + + mms.scheduleBuild2(0).get(); + + Address[] senders = yourInbox.get(0).getFrom(); + assertEquals(1, senders.length); + assertEquals("me ", senders[0].toString()); + + return yourInbox; + } + +}