diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 19b973bbb9..d12d1d3859 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -174,6 +174,12 @@ public abstract class AbstractProject
,R extends A */ protected volatile boolean disabled; + /** + * True to keep builds of this project in queue when downstream projects are + * building. False by default to keep from breaking existing behavior. + */ + protected volatile boolean blockBuildWhenDownstreamBuilding = false; + /** * True to keep builds of this project in queue when upstream projects are * building. False by default to keep from breaking existing behavior. @@ -500,6 +506,15 @@ public abstract class AbstractProject
,R extends A return true; } + public boolean blockBuildWhenDownstreamBuilding() { + return blockBuildWhenDownstreamBuilding; + } + + public void setBlockBuildWhenDownstreamBuilding(boolean b) throws IOException { + blockBuildWhenDownstreamBuilding = b; + save(); + } + public boolean blockBuildWhenUpstreamBuilding() { return blockBuildWhenUpstreamBuilding; } @@ -998,6 +1013,22 @@ public abstract class AbstractProject
,R extends A return Messages.AbstractProject_BuildInProgress(lbn, eta); } } + + /** + * Because the downstream build is in progress, and we are configured to wait for that. + */ + public static class BecauseOfDownstreamBuildInProgress extends CauseOfBlockage { + public final AbstractProject,?> up; + + public BecauseOfDownstreamBuildInProgress(AbstractProject,?> up) { + this.up = up; + } + + @Override + public String getShortDescription() { + return Messages.AbstractProject_DownstreamBuildInProgress(up.getName()); + } + } /** * Because the upstream build is in progress, and we are configured to wait for that. @@ -1018,7 +1049,11 @@ public abstract class AbstractProject
,R extends A public CauseOfBlockage getCauseOfBlockage() { if (isBuilding() && !isConcurrentBuild()) return new BecauseOfBuildInProgress(getLastBuild()); - if (blockBuildWhenUpstreamBuilding()) { + if (blockBuildWhenDownstreamBuilding()) { + AbstractProject,?> bup = getBuildingDownstream(); + if (bup!=null) + return new BecauseOfDownstreamBuildInProgress(bup); + } else if (blockBuildWhenUpstreamBuilding()) { AbstractProject,?> bup = getBuildingUpstream(); if (bup!=null) return new BecauseOfUpstreamBuildInProgress(bup); @@ -1026,6 +1061,24 @@ public abstract class AbstractProject
,R extends A return null; } + /** + * Returns the project if any of the downstream project (or itself) is either + * building or is in the queue. + *
+ * This means eventually there will be an automatic triggering of
+ * the given project (provided that all builds went smoothly.)
+ */
+ protected AbstractProject getBuildingDownstream() {
+ DependencyGraph graph = Hudson.getInstance().getDependencyGraph();
+ Set ,R extends A
} else {
scmCheckoutRetryCount = null;
}
+ blockBuildWhenDownstreamBuilding = req.getParameter("blockBuildWhenDownstreamBuilding")!=null;
blockBuildWhenUpstreamBuilding = req.getParameter("blockBuildWhenUpstreamBuilding")!=null;
if(req.getParameter("hasSlaveAffinity")!=null) {
diff --git a/core/src/main/resources/hudson/model/AbstractItem/configure-common.jelly b/core/src/main/resources/hudson/model/AbstractItem/configure-common.jelly
index fb40c91665..cb33be6aa6 100644
--- a/core/src/main/resources/hudson/model/AbstractItem/configure-common.jelly
+++ b/core/src/main/resources/hudson/model/AbstractItem/configure-common.jelly
@@ -61,6 +61,7 @@ THE SOFTWARE.