mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 14:02:22 +00:00
reimplemented a fix to #747 as the list of culprits is really not specific to e-mail.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@4689 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
95410ceae1
commit
e9ffeeee48
7 files changed
+91
-48
No files matched your search
@@ -1,11 +1,6 @@
|
||||
package hudson.matrix;
|
||||
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.Executor;
|
||||
import hudson.model.Hudson;
|
||||
import hudson.model.Queue;
|
||||
import hudson.model.*;
|
||||
import hudson.tasks.Publisher;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
@@ -13,11 +8,10 @@ import org.kohsuke.stapler.StaplerResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Build of {@link MatrixProject}.
|
||||
@@ -141,7 +135,7 @@ public class MatrixBuild extends AbstractBuild<MatrixProject,MatrixBuild> {
|
||||
}
|
||||
}
|
||||
|
||||
public void post(BuildListener listener) throws IOException, InterruptedException {
|
||||
public void post2(BuildListener listener) throws Exception {
|
||||
for (MatrixAggregator a : aggregators)
|
||||
a.endBuild();
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ public class MavenBuild extends AbstractBuild<MavenModule,MavenBuild> {
|
||||
}
|
||||
}
|
||||
|
||||
public void post(BuildListener listener) throws IOException, InterruptedException {
|
||||
public void post2(BuildListener listener) throws Exception {
|
||||
for (MavenReporter reporter : reporters)
|
||||
reporter.end(MavenBuild.this,launcher,listener);
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ public final class MavenModuleSetBuild extends AbstractBuild<MavenModuleSet,Mave
|
||||
}
|
||||
}
|
||||
|
||||
public void post(BuildListener listener) {
|
||||
public void post2(BuildListener listener) throws Exception {
|
||||
if(project.isAggregatorStyleBuild()) {
|
||||
// schedule downstream builds. for non aggregator style builds,
|
||||
// this is done by each module
|
||||
|
||||
@@ -3,35 +3,31 @@ package hudson.model;
|
||||
import hudson.Launcher;
|
||||
import hudson.Proc.LocalProc;
|
||||
import hudson.Util;
|
||||
import hudson.util.AdaptedIterator;
|
||||
import hudson.matrix.MatrixConfiguration;
|
||||
import org.kohsuke.stapler.export.Exported;
|
||||
import hudson.tasks.Fingerprinter.FingerprintAction;
|
||||
import hudson.tasks.test.AbstractTestResultAction;
|
||||
import hudson.tasks.Builder;
|
||||
import hudson.maven.MavenBuild;
|
||||
import hudson.model.Fingerprint.BuildPtr;
|
||||
import hudson.model.Fingerprint.RangeSet;
|
||||
import static hudson.model.Hudson.isWindows;
|
||||
import hudson.model.listeners.SCMListener;
|
||||
import hudson.model.Fingerprint.RangeSet;
|
||||
import hudson.model.Fingerprint.BuildPtr;
|
||||
import hudson.scm.CVSChangeLogParser;
|
||||
import hudson.scm.ChangeLogParser;
|
||||
import hudson.scm.ChangeLogSet;
|
||||
import hudson.scm.ChangeLogSet.Entry;
|
||||
import hudson.scm.SCM;
|
||||
import hudson.tasks.Builder;
|
||||
import hudson.tasks.Fingerprinter.FingerprintAction;
|
||||
import hudson.tasks.test.AbstractTestResultAction;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import org.kohsuke.stapler.export.Exported;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Calendar;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Base implementation of {@link Run}s that build software.
|
||||
@@ -65,6 +61,21 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
|
||||
*/
|
||||
private volatile transient ChangeLogSet<? extends Entry> changeSet;
|
||||
|
||||
/**
|
||||
* Cumulative list of people who contributed to the build problem.
|
||||
*
|
||||
* <p>
|
||||
* This is a list of {@link User#getId() user ids} who made a change
|
||||
* since the last non-broken build. Can be null (which should be
|
||||
* treated like empty set), because of the compatibility.
|
||||
*
|
||||
* <p>
|
||||
* This field is semi-final --- once set the value will never be modified.
|
||||
*
|
||||
* @since 1.137
|
||||
*/
|
||||
private volatile Set<String> culprits;
|
||||
|
||||
protected AbstractBuild(P job) throws IOException {
|
||||
super(job);
|
||||
}
|
||||
@@ -99,6 +110,46 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
|
||||
return builtOn;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of users who committed a change since the last non-broken build till now.
|
||||
*
|
||||
* <p>
|
||||
* This
|
||||
*
|
||||
* @return
|
||||
* can be empty but never null.
|
||||
*/
|
||||
@Exported
|
||||
public Set<User> getCulprits() {
|
||||
if(culprits==null) {
|
||||
Set<User> r = new HashSet<User>();
|
||||
if(getPreviousBuild()!=null && isBuilding() && getPreviousBuild().getResult().isWorseThan(Result.UNSTABLE)) {
|
||||
// we are still building, so this is just the current latest information,
|
||||
// but we seems to be failing so far, so inherit culprits from the previous build.
|
||||
// isBuilding() check is to avoid recursion when loading data from old Hudson, which doesn't record
|
||||
// this information
|
||||
r.addAll(getPreviousBuild().getCulprits());
|
||||
}
|
||||
for( Entry e : getChangeSet() )
|
||||
r.add(e.getAuthor());
|
||||
return r;
|
||||
}
|
||||
|
||||
return new AbstractSet<User>() {
|
||||
public Iterator<User> iterator() {
|
||||
return new AdaptedIterator<String,User>(culprits.iterator()) {
|
||||
protected User adapt(String id) {
|
||||
return User.get(id);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return culprits.size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected abstract class AbstractRunner implements Runner {
|
||||
/**
|
||||
* Since configuration can be changed while a build is in progress,
|
||||
@@ -180,6 +231,23 @@ public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends Abs
|
||||
* Return a non-null value to abort the build right there with the specified result code.
|
||||
*/
|
||||
protected abstract Result doRun(BuildListener listener) throws Exception;
|
||||
|
||||
/**
|
||||
* @see #post(BuildListener)
|
||||
*/
|
||||
protected abstract void post2(BuildListener listener) throws Exception;
|
||||
|
||||
public final void post(BuildListener listener) throws Exception {
|
||||
try {
|
||||
post2(listener);
|
||||
} finally {
|
||||
// update the culprit list
|
||||
HashSet<String> r = new HashSet<String>();
|
||||
for (User u : getCulprits())
|
||||
r.add(u.getId());
|
||||
culprits = r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,8 +71,6 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
|
||||
*/
|
||||
private Integer quietPeriod = null;
|
||||
|
||||
public transient Set<User> culprits;
|
||||
|
||||
/**
|
||||
* If this project is configured to be only built on a certain label,
|
||||
* this value will be set to that label.
|
||||
|
||||
@@ -136,7 +136,7 @@ public abstract class Build <P extends Project<P,B>,B extends Build<P,B>>
|
||||
return null;
|
||||
}
|
||||
|
||||
public void post(BuildListener listener) throws IOException, InterruptedException {
|
||||
public void post2(BuildListener listener) throws IOException, InterruptedException {
|
||||
// run all of them even if one of them failed
|
||||
for( Publisher bs : project.getPublishers().values() )
|
||||
bs.perform(Build.this, launcher, listener);
|
||||
|
||||
@@ -2,13 +2,8 @@ package hudson.tasks;
|
||||
|
||||
import hudson.FilePath;
|
||||
import hudson.Util;
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.User;
|
||||
import hudson.model.*;
|
||||
import hudson.scm.ChangeLogSet;
|
||||
import hudson.scm.ChangeLogSet.Entry;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.Message;
|
||||
@@ -21,7 +16,6 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
@@ -117,9 +111,6 @@ public class MailSender<P extends AbstractProject<P, B>, B extends AbstractBuild
|
||||
appendBuildUrl(build, buf);
|
||||
msg.setText(buf.toString());
|
||||
|
||||
// Reset the list of culprits
|
||||
build.getProject().culprits.clear();
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
@@ -245,20 +236,12 @@ public class MailSender<P extends AbstractProject<P, B>, B extends AbstractBuild
|
||||
while (tokens.hasMoreTokens())
|
||||
rcp.add(new InternetAddress(tokens.nextToken()));
|
||||
if (sendToIndividuals) {
|
||||
if(debug) {
|
||||
int count = 0;
|
||||
for (Entry cs : build.getChangeSet()) count++;
|
||||
listener.getLogger().println("Trying to send e-mails to individuals who broke the build. sizeof(changeset)=="+count);
|
||||
}
|
||||
Set<User> culprits = build.getCulprits();
|
||||
|
||||
if (build.getProject().culprits == null)
|
||||
build.getProject().culprits = new HashSet<User>();
|
||||
if(debug)
|
||||
listener.getLogger().println("Trying to send e-mails to individuals who broke the build. sizeof(culprits)=="+culprits.size());
|
||||
|
||||
for (Entry change : build.getChangeSet()) {
|
||||
build.getProject().culprits.add(change.getAuthor());
|
||||
}
|
||||
|
||||
for (User a : build.getProject().culprits) {
|
||||
for (User a : culprits) {
|
||||
String adrs = Util.fixEmpty(a.getProperty(Mailer.UserProperty.class).getAddress());
|
||||
if(debug)
|
||||
listener.getLogger().println(" User "+a.getId()+" -> "+adrs);
|
||||
|
||||
Reference in new issue
Block a user