提交 e83a0b50 编写于 作者: M mleinart

[FIXED HUDSON-7046] - Add "Block build when downstream project is building" option

上级 fa228156
......@@ -174,6 +174,12 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,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<P extends AbstractProject<P,R>,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<P extends AbstractProject<P,R>,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<P extends AbstractProject<P,R>,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<P extends AbstractProject<P,R>,R extends A
return null;
}
/**
* Returns the project if any of the downstream project (or itself) is either
* building or is in the queue.
* <p>
* 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<AbstractProject> tups = graph.getTransitiveDownstream(this);
tups.add(this);
for (AbstractProject tup : tups) {
if(tup!=this && (tup.isBuilding() || tup.isInQueue()))
return tup;
}
return null;
}
/**
* Returns the project if any of the upstream project (or itself) is either
* building or is in the queue.
......@@ -1570,6 +1623,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
} else {
scmCheckoutRetryCount = null;
}
blockBuildWhenDownstreamBuilding = req.getParameter("blockBuildWhenDownstreamBuilding")!=null;
blockBuildWhenUpstreamBuilding = req.getParameter("blockBuildWhenUpstreamBuilding")!=null;
if(req.getParameter("hasSlaveAffinity")!=null) {
......
......@@ -61,6 +61,7 @@ THE SOFTWARE.
<p:config-quietPeriod />
<p:config-retryCount />
<p:config-blockWhenUpstreamBuilding />
<p:config-blockWhenDownstreamBuilding />
<st:include page="configure-advanced.jelly" optional="true" />
</f:advanced>
</f:section>
......
......@@ -33,6 +33,7 @@ AbstractProject.Pronoun=Project
AbstractProject.Aborted=Aborted
AbstractProject.BuildInProgress=Build #{0} is already in progress{1}
AbstractProject.UpstreamBuildInProgress=Upstream project {0} is already building.
AbstractProject.DownstreamBuildInProgress=Downstream project {0} is already building.
AbstractProject.Disabled=Build disabled
AbstractProject.ETA=\ (ETA:{0})
AbstractProject.NoBuilds=No existing build. Scheduling a new one.
......@@ -285,4 +286,4 @@ CLI.quiet-down.shortDescription=Quiet down Hudson, in preparation for a restart.
CLI.cancel-quiet-down.shortDescription=Cancel the effect of the "quiet-down" command.
CLI.reload-configuration.shortDescription=Discard all the loaded data in memory and reload everything from file system. Useful when you modified config files directly on disk.
BuildAuthorizationToken.InvalidTokenProvided=Invalid token provided.
\ No newline at end of file
BuildAuthorizationToken.InvalidTokenProvided=Invalid token provided.
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Shinod
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!-- Block build when upstream dependency is building -->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:optionalBlock name="blockBuildWhenDownstreamBuilding"
title="${%Block build when downstream project is building}"
help="/help/project-config/block-downstream-building.html"
checked="${it.blockBuildWhenDownstreamBuilding()}" />
</j:jelly>
<div>
When this option is checked, Hudson will prevent the project from building when a parent of this project is in the queue, or building. The parents include the direct as well as the transitive parents.
</div>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册