Skip to content

Commit

Permalink
[FIXED JENKINS-21903] Unless the user has requested to block when ups…
Browse files Browse the repository at this point in the history
…tream is building, do not skip triggering a downstream build just because an upstream is building.
  • Loading branch information
jglick committed Aug 20, 2014
1 parent c1de612 commit 0ff6a1b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/main/java/hudson/maven/AbstractMavenProject.java
Expand Up @@ -24,6 +24,7 @@
package hudson.maven;

import hudson.Util;
import hudson.console.ModelHyperlinkNote;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
Expand Down Expand Up @@ -76,13 +77,12 @@ public boolean shouldTriggerBuild(AbstractBuild build,

// Check to see if any of its upstream dependencies are already building or in queue.
AbstractMavenProject<?,?> parent = (AbstractMavenProject<?,?>) getUpstreamProject();
if (areUpstreamsBuilding(downstreamProject, parent)) {
listener.getLogger().println("Not triggering " + downstreamProject.getFullDisplayName() + " because it has dependencies already building or in queue");
if (areUpstreamsBuilding(downstreamProject, parent, listener)) {
return false;
}
// Check to see if any of its upstream dependencies are in this list of downstream projects.
else if (inDownstreamProjects(downstreamProject)) {
listener.getLogger().println("Not triggering " + downstreamProject.getFullDisplayName() + " because it has dependencies in the downstream project list");
listener.getLogger().println("Not triggering " + ModelHyperlinkNote.encodeTo(downstreamProject) + " because it has dependencies in the downstream project list");
return false;
}
else {
Expand All @@ -101,7 +101,7 @@ else if (inDownstreamProjects(downstreamProject)) {
if(ulb==null) {
// if no usable build is available from the upstream,
// then we have to wait at least until this build is ready
listener.getLogger().println("Not triggering " + downstreamProject.getFullDisplayName() + " because another upstream " + up.getFullDisplayName() + " has no successful build");
listener.getLogger().println("Not triggering " + ModelHyperlinkNote.encodeTo(downstreamProject) + " because another upstream " + ModelHyperlinkNote.encodeTo(up) + " has no successful build");
return false;
}

Expand All @@ -115,7 +115,7 @@ else if (inDownstreamProjects(downstreamProject)) {
assert ulb.getNumber()>=n;
}
}
listener.getLogger().println("Decided to trigger " + downstreamProject.getFullDisplayName());
// No real need to print a message that downstreamProject is being triggered, since BuildTrigger will note this anyway
return true;
}

Expand All @@ -138,12 +138,19 @@ else if (inDownstreamProjects(downstreamProject)) {
*/
@SuppressWarnings("rawtypes")
private boolean areUpstreamsBuilding(AbstractProject<?,?> downstreamProject,
AbstractProject<?,?> excludeProject) {
AbstractProject<?,?> excludeProject, TaskListener listener) {
DependencyGraph graph = Jenkins.getInstance().getDependencyGraph();
Set<AbstractProject> tups = graph.getTransitiveUpstream(downstreamProject);
for (AbstractProject tup : tups) {
if(tup!=excludeProject && (tup.isBuilding() || tup.isInQueue()))
return true;
if (tup != excludeProject && (tup.isBuilding() || tup.isInQueue())) {
if (downstreamProject.getRootProject().blockBuildWhenUpstreamBuilding()) {
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.");
return false; // do not bother printing messages about other upstreams
}
}
}
return false;
}
Expand Down

0 comments on commit 0ff6a1b

Please sign in to comment.