Skip to content
Permalink
Browse files

[JENKINS-21903] Amending 0ff6a1b with flag blockTriggerWhenBuilding t…

…o control the new behavior, rather than overloading blockBuildWhenUpstreamBuilding.

Allows more detailed control that may be needed in some setups.
Also preserves the default behavior from older plugin versions to avoid surprises.
  • Loading branch information...
jglick committed Sep 25, 2014
1 parent 6e8c99d commit 8aed1aa0e352d51229daba470d1664488a3441c4
@@ -143,11 +143,12 @@ private boolean areUpstreamsBuilding(AbstractProject<?,?> downstreamProject,
Set<AbstractProject> tups = graph.getTransitiveUpstream(downstreamProject);
for (AbstractProject tup : tups) {
if (tup != excludeProject && (tup.isBuilding() || tup.isInQueue())) {
if (downstreamProject.getRootProject().blockBuildWhenUpstreamBuilding()) {
AbstractProject<?,?> tupr = tup.getRootProject();
if (tupr instanceof MavenModuleSet && ((MavenModuleSet) tupr).getBlockTriggerWhenBuilding()) {
listener.getLogger().println("Not triggering " + ModelHyperlinkNote.encodeTo(downstreamProject) + " because it has a dependency " + ModelHyperlinkNote.encodeTo(tup) + " already building or in queue");
return true;
} else {
listener.getLogger().println("Could be blocking trigger of " + ModelHyperlinkNote.encodeTo(downstreamProject) + " (due to a dependency on " + ModelHyperlinkNote.encodeTo(tup) + ") but it is not configured to block when upstream is building.");
listener.getLogger().println("Could be blocking trigger of " + ModelHyperlinkNote.encodeTo(downstreamProject) + " (due to a dependency on " + ModelHyperlinkNote.encodeTo(tup) + ") but the upstream is not configured to block while building.");
return false; // do not bother printing messages about other upstreams
}
}
@@ -277,6 +277,8 @@
*/
private boolean disableTriggerDownstreamProjects;

private Boolean blockTriggerWhenBuilding;

/**
* used temporary during maven build to store file path
* @since 1.426
@@ -910,6 +912,14 @@ public void setDisableTriggerDownstreamProjects(boolean disableTriggerDownstream
this.disableTriggerDownstreamProjects = disableTriggerDownstreamProjects;
}

public boolean getBlockTriggerWhenBuilding() {
return blockTriggerWhenBuilding == null || blockTriggerWhenBuilding;
}

public void setBlockTriggerWhenBuilding(boolean blockTriggerWhenBuilding) {
this.blockTriggerWhenBuilding = blockTriggerWhenBuilding;
}

public MavenModule getRootModule() {
if(rootModule==null) return null;
return modules.get(rootModule);
@@ -1197,7 +1207,14 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
reporters.rebuild(req,json,MavenReporters.getConfigurableList());
publishers.rebuildHetero(req, json, Publisher.all(), "publisher");
buildWrappers.rebuild(req, json, BuildWrappers.getFor(this));
disableTriggerDownstreamProjects = req.hasParameter("maven.disableTriggerDownstreamProjects");
JSONObject enableTriggerDownstreamProjects = json.optJSONObject("enableTriggerDownstreamProjects");
if (enableTriggerDownstreamProjects == null) {
disableTriggerDownstreamProjects = true;
blockTriggerWhenBuilding = null;
} else {
disableTriggerDownstreamProjects = false;
blockTriggerWhenBuilding = enableTriggerDownstreamProjects.has("blockTriggerWhenBuilding");
}

runPostStepsIfResult = Result.fromString(req.getParameter( "post-steps.runIfResult"));
prebuilders.rebuildHetero(req,json, Builder.all(), "prebuilder");
@@ -98,10 +98,19 @@ THE SOFTWARE.
title="${%Disable automatic fingerprinting of consumed and produced artifacts}"
help="/plugin/maven-plugin/fingerprintingDisabled.html"
checked="${it.isFingerprintingDisabled()}" />
<f:optionalBlock name="maven.disableTriggerDownstreamProjects"
title="${%Disable triggering of downstream projects}"
<f:optionalBlock name="maven.enableTriggerDownstreamProjects"
title="${%Enable triggering of downstream projects}"
help="/plugin/maven-plugin/downstreamDisabled.html"
checked="${it.isDisableTriggerDownstreamProjects()}" />
checked="${!it.disableTriggerDownstreamProjects}">
<f:nested>
<table width="100%">
<f:optionalBlock name="maven.blockTriggerWhenBuilding"
title="${%Block downstream trigger when building}"
help="/plugin/maven-plugin/blockTriggerWhenBuilding.html"
checked="${it.blockTriggerWhenBuilding}"/>
</table>
</f:nested>
</f:optionalBlock>
<f:optionalBlock name="maven.perModuleBuild" title="${%Build modules in parallel}" help="/plugin/maven-plugin/aggregator.html"
checked="${!it.aggregatorStyleBuild}" />
<f:optionalBlock name="maven.usePrivateRepository" title="${%Use private Maven repository}" help="/plugin/maven-plugin/private-repository.html"
@@ -0,0 +1,12 @@
<div>
<p>
By default when a newer build of an upstream project is building (or in queue),
an earlier build will not trigger builds of downstream modules.
This is under the assumption that those builds would soon be superseded and are not of interest.
</p>
<p>
You can however disable this logic on the upstream project, which will result in a fuller sequence of downstream builds.
This is not be confused with <b>Block build when upstream project is building</b> (marked on the other project),
which controls <em>scheduling</em> of the downstream project once it has been triggered.
</p>
</div>
@@ -67,4 +67,26 @@ public void testExplicitFingerprints() throws Exception {
assertNull(jenkins.getDescriptorByType(MavenFingerprinter.DescriptorImpl.class).newAutoInstance(m.getRootModule()));
}

@Bug(21903)
public void testConfigRoundtripTriggers() throws Exception {
// New project defaults to trigger with blocks:
MavenModuleSet m = createMavenProject();
assertFalse(m.isDisableTriggerDownstreamProjects());
assertTrue(m.getBlockTriggerWhenBuilding());
configRoundtrip(m);
assertFalse(m.isDisableTriggerDownstreamProjects());
assertTrue(m.getBlockTriggerWhenBuilding());
// No trigger:
m.setDisableTriggerDownstreamProjects(true);
configRoundtrip(m);
assertTrue(m.isDisableTriggerDownstreamProjects());
// blockTriggerWhenBuilding irrelevant in this case, I think (perhaps not in exotic case involving multiple upstreams)
// Unconditional trigger:
m.setDisableTriggerDownstreamProjects(false);
m.setBlockTriggerWhenBuilding(false);
configRoundtrip(m);
assertFalse(m.isDisableTriggerDownstreamProjects());
assertFalse(m.getBlockTriggerWhenBuilding());
}

}

0 comments on commit 8aed1aa

Please sign in to comment.
You can’t perform that action at this time.