Skip to content

Commit

Permalink
[JENKINS-21903] Amending 0ff6a1b with flag blockTriggerWhenBuilding t…
Browse files Browse the repository at this point in the history
…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 8aed1aa
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/main/java/hudson/maven/AbstractMavenProject.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ private boolean areUpstreamsBuilding(AbstractProject<?,?> downstreamProject,
Set<AbstractProject> tups = graph.getTransitiveUpstream(downstreamProject); Set<AbstractProject> tups = graph.getTransitiveUpstream(downstreamProject);
for (AbstractProject tup : tups) { for (AbstractProject tup : tups) {
if (tup != excludeProject && (tup.isBuilding() || tup.isInQueue())) { 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"); listener.getLogger().println("Not triggering " + ModelHyperlinkNote.encodeTo(downstreamProject) + " because it has a dependency " + ModelHyperlinkNote.encodeTo(tup) + " already building or in queue");
return true; return true;
} else { } 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 return false; // do not bother printing messages about other upstreams
} }
} }
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/hudson/maven/MavenModuleSet.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ public class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,MavenMod
*/ */
private boolean disableTriggerDownstreamProjects; private boolean disableTriggerDownstreamProjects;


private Boolean blockTriggerWhenBuilding;

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


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

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

public MavenModule getRootModule() { public MavenModule getRootModule() {
if(rootModule==null) return null; if(rootModule==null) return null;
return modules.get(rootModule); return modules.get(rootModule);
Expand Down Expand Up @@ -1197,7 +1207,14 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
reporters.rebuild(req,json,MavenReporters.getConfigurableList()); reporters.rebuild(req,json,MavenReporters.getConfigurableList());
publishers.rebuildHetero(req, json, Publisher.all(), "publisher"); publishers.rebuildHetero(req, json, Publisher.all(), "publisher");
buildWrappers.rebuild(req, json, BuildWrappers.getFor(this)); 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")); runPostStepsIfResult = Result.fromString(req.getParameter( "post-steps.runIfResult"));
prebuilders.rebuildHetero(req,json, Builder.all(), "prebuilder"); prebuilders.rebuildHetero(req,json, Builder.all(), "prebuilder");
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -98,10 +98,19 @@ THE SOFTWARE.
title="${%Disable automatic fingerprinting of consumed and produced artifacts}" title="${%Disable automatic fingerprinting of consumed and produced artifacts}"
help="/plugin/maven-plugin/fingerprintingDisabled.html" help="/plugin/maven-plugin/fingerprintingDisabled.html"
checked="${it.isFingerprintingDisabled()}" /> checked="${it.isFingerprintingDisabled()}" />
<f:optionalBlock name="maven.disableTriggerDownstreamProjects" <f:optionalBlock name="maven.enableTriggerDownstreamProjects"
title="${%Disable triggering of downstream projects}" title="${%Enable triggering of downstream projects}"
help="/plugin/maven-plugin/downstreamDisabled.html" 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" <f:optionalBlock name="maven.perModuleBuild" title="${%Build modules in parallel}" help="/plugin/maven-plugin/aggregator.html"
checked="${!it.aggregatorStyleBuild}" /> checked="${!it.aggregatorStyleBuild}" />
<f:optionalBlock name="maven.usePrivateRepository" title="${%Use private Maven repository}" help="/plugin/maven-plugin/private-repository.html" <f:optionalBlock name="maven.usePrivateRepository" title="${%Use private Maven repository}" help="/plugin/maven-plugin/private-repository.html"
Expand Down
12 changes: 12 additions & 0 deletions src/main/webapp/blockTriggerWhenBuilding.html
Original file line number Original file line Diff line number Diff line change
@@ -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>
22 changes: 22 additions & 0 deletions src/test/java/hudson/maven/MavenModuleSetTest.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,4 +67,26 @@ public void testExplicitFingerprints() throws Exception {
assertNull(jenkins.getDescriptorByType(MavenFingerprinter.DescriptorImpl.class).newAutoInstance(m.getRootModule())); 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.