Skip to content

Commit

Permalink
[FIXED JENKINS-5695] Jenkins sending too many emails for Maven module…
Browse files Browse the repository at this point in the history
… failure

Originally-Committed-As: 4b2e23b197fa40612fcf59c5eb3dd81a8a5fd654
  • Loading branch information
imod committed Dec 25, 2011
1 parent 682693f commit 31ccddb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/main/java/hudson/maven/MavenModuleSet.java
Expand Up @@ -185,6 +185,14 @@ public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenMod
* @since 1.223
*/
private boolean usePrivateRepository = false;

/**
* If true, the build will send a failure e-mail for each failing maven module.
* Defaults to <code>true</code> to simulate old behavior.
* <p>
* see JENKINS-5695.
*/
private Boolean perModuleEmail = Boolean.TRUE;

/**
* If true, do not automatically schedule a build when one of the project dependencies is built.
Expand Down Expand Up @@ -436,6 +444,10 @@ public boolean usesPrivateRepository() {
return usePrivateRepository;
}

public boolean isPerModuleEmail() {
return perModuleEmail;
}

public boolean ignoreUpstremChanges() {
return ignoreUpstremChanges;
}
Expand Down Expand Up @@ -665,6 +677,10 @@ public ModuleName call(MavenModule module) {
}
postbuilders.setOwner(this);

if(perModuleEmail == null){
perModuleEmail = Boolean.TRUE;
}

updateTransientActions();
}

Expand Down Expand Up @@ -987,6 +1003,7 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
mavenName = req.getParameter("maven_version");
aggregatorStyleBuild = !req.hasParameter("maven.perModuleBuild");
usePrivateRepository = req.hasParameter("maven.usePrivateRepository");
perModuleEmail = req.hasParameter("maven.perModuleEmail");
ignoreUpstremChanges = !json.has("triggerByDependency");
runHeadless = req.hasParameter("maven.runHeadless");
incrementalBuild = req.hasParameter("maven.incrementalBuild");
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/hudson/maven/reporters/MavenMailer.java
Expand Up @@ -48,9 +48,12 @@ public class MavenMailer extends MavenReporter {
public String recipients;
public boolean dontNotifyEveryUnstableBuild;
public boolean sendToIndividuals;
public boolean perModuleEmail;

public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
new MailSender(recipients,dontNotifyEveryUnstableBuild,sendToIndividuals).execute(build,listener);
if(perModuleEmail) {
new MailSender(recipients,dontNotifyEveryUnstableBuild,sendToIndividuals).execute(build,listener);
}
return true;
}

Expand All @@ -74,6 +77,7 @@ public MavenReporter newInstance(StaplerRequest req, JSONObject formData) throws
MavenMailer m = new MavenMailer();
req.bindParameters(m,"mailer_");
m.dontNotifyEveryUnstableBuild = req.getParameter("mailer_notifyEveryUnstableBuild")==null;
m.perModuleEmail = req.hasParameter("maven.perModuleEmail");
return m;
}
}
Expand Down
Expand Up @@ -98,6 +98,8 @@ THE SOFTWARE.
checked="${!it.aggregatorStyleBuild}" />
<f:optionalBlock name="maven.usePrivateRepository" title="${%Use private Maven repository}" help="/plugin/maven-plugin/private-repository.html"
checked="${it.usesPrivateRepository()}" />
<f:optionalBlock name="maven.perModuleEmail" title="${%Send e-mail for each failed module}" help="/plugin/maven-plugin/per-module-email.html"
checked="${it.isPerModuleEmail()}" />
<f:optionalBlock name="maven.resolveDependencies" title="${%Resolve Dependencies during Pom parsing}"
checked="${it.isResolveDependencies()}" />
<f:optionalBlock name="maven.runHeadless" title="${%Run Headless}" help="/plugin/maven-plugin/run-headless.html"
Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/per-module-email.html
@@ -0,0 +1,3 @@
<div>
If checked, Jenkins will send an e-mail notifications for each module (e.g. failed, unstable).
</div>

0 comments on commit 31ccddb

Please sign in to comment.