mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 05:22:22 +00:00
added downstream build trigger support.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@4488 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
52debdc297
commit
cb7a23cec4
2 files changed
+34
-6
No files matched your search
@@ -21,17 +21,18 @@ import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -268,6 +269,13 @@ public class MavenBuild extends AbstractBuild<MavenModule,MavenBuild> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the build for which this proxy is created.
|
||||
*/
|
||||
public MavenBuild owner() {
|
||||
return MavenBuild.this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the build as aborted. This method is used when the aggregated build
|
||||
* failed before it didn't even get to this module.
|
||||
@@ -332,20 +340,27 @@ public class MavenBuild extends AbstractBuild<MavenModule,MavenBuild> {
|
||||
reporter.end(MavenBuild.this,launcher,listener);
|
||||
|
||||
if(getResult().isBetterOrEqualTo(Result.SUCCESS))
|
||||
scheduleDownstreamBuilds(listener);
|
||||
scheduleDownstreamBuilds(listener,new HashSet<AbstractProject>());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules all the downstream builds.
|
||||
*
|
||||
* @param downstreams
|
||||
* List of downstream jobs that are already scheduled.
|
||||
* The method will add jobs that it triggered here,
|
||||
* and won't try to trigger jobs that are already in this list.
|
||||
* @param listener
|
||||
* Where the progress reports go.
|
||||
*/
|
||||
/*package*/ final void scheduleDownstreamBuilds(BuildListener listener) {
|
||||
/*package*/ final void scheduleDownstreamBuilds(BuildListener listener, Set<AbstractProject> downstreams) {
|
||||
// trigger dependency builds
|
||||
DependencyGraph graph = Hudson.getInstance().getDependencyGraph();
|
||||
for( AbstractProject<?,?> down : getParent().getDownstreamProjects()) {
|
||||
if(downstreams.contains(down))
|
||||
continue; // already triggered
|
||||
|
||||
if(debug)
|
||||
listener.getLogger().println("Considering whether to trigger "+down+" or not");
|
||||
|
||||
@@ -409,6 +424,7 @@ public class MavenBuild extends AbstractBuild<MavenModule,MavenBuild> {
|
||||
|
||||
if(trigger) {
|
||||
listener.getLogger().println("Triggering a new build of "+down.getName());
|
||||
downstreams.add(down);
|
||||
down.scheduleBuild();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import hudson.model.Build;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.Hudson;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.remoting.VirtualChannel;
|
||||
import hudson.util.ArgumentListBuilder;
|
||||
import hudson.util.IOException2;
|
||||
@@ -222,6 +223,8 @@ public final class MavenModuleSetBuild extends AbstractBuild<MavenModuleSet,Mave
|
||||
* and triggers module builds.
|
||||
*/
|
||||
private class RunnerImpl extends AbstractRunner {
|
||||
private Map<ModuleName,MavenBuild.ProxyImpl2> proxies;
|
||||
|
||||
protected Result doRun(final BuildListener listener) throws Exception {
|
||||
PrintStream logger = listener.getLogger();
|
||||
try {
|
||||
@@ -279,7 +282,7 @@ public final class MavenModuleSetBuild extends AbstractBuild<MavenModuleSet,Mave
|
||||
project.getRootModule().scheduleBuild();
|
||||
} else {
|
||||
SplittableBuildListener slistener = new SplittableBuildListener(listener);
|
||||
Map<ModuleName,MavenBuild.ProxyImpl2> proxies = new HashMap<ModuleName,MavenBuild.ProxyImpl2>();
|
||||
proxies = new HashMap<ModuleName, ProxyImpl2>();
|
||||
for (MavenModule m : modules.values())
|
||||
proxies.put(m.getModuleName(),m.newBuild().new ProxyImpl2(slistener));
|
||||
|
||||
@@ -324,6 +327,15 @@ public final class MavenModuleSetBuild extends AbstractBuild<MavenModuleSet,Mave
|
||||
}
|
||||
|
||||
public void post(BuildListener listener) {
|
||||
if(aggregatorStyle) {
|
||||
// schedule downstream builds. for non aggregator style builds,
|
||||
// this is done by each module
|
||||
if(getResult().isBetterOrEqualTo(Result.SUCCESS)) {
|
||||
HashSet<AbstractProject> downstreams = new HashSet<AbstractProject>(project.modules.values());
|
||||
for (ProxyImpl2 p : proxies.values())
|
||||
p.owner().scheduleDownstreamBuilds(listener,downstreams);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user