Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel downstream builds if was triggered by GHPRB. #738

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/main/java/org/jenkinsci/plugins/ghprb/Ghprb.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.Cause;
import hudson.model.Cause.UpstreamCause;
import hudson.model.Item;
import hudson.model.Job;
import hudson.model.Result;
Expand Down Expand Up @@ -407,6 +408,27 @@ public static GhprbCause getCause(Run<?, ?> build) {
return (GhprbCause) cause;
}

/**
* Return a GhprbCause if the build is a downstream build that has been trigger
* by Ghprb plugin
* @param build to validate
* @return ghprbCause
*/
public static GhprbCause isDownstreamBuild(Run<?, ?> build) {
Cause cause = build.getCause(UpstreamCause.class);
if (cause == null) {
return null;
}

UpstreamCause upstreamCause = (UpstreamCause) cause;
for (Cause itemCause: upstreamCause.getUpstreamCauses()) {
if (itemCause instanceof GhprbCause) {
return (GhprbCause) cause;
}
}
return null;
}


public static GhprbTrigger extractTrigger(Run<?, ?> build) {
return extractTrigger(build.getParent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,17 @@ private void cancelCurrentBuilds(Job<?, ?> project,
if (!run.isBuilding() && !run.hasntStartedYet()) {
break;
}

GhprbCause cause = Ghprb.getCause(run);
if (cause == null) {
continue;
// Validate that if the build is triggered by a GHPRB build and
// if so update the cause to stop also this build.
cause = Ghprb.isDownstreamBuild(run);
if (cause == null) {
continue;
}
}

if (cause.getPullID() == prId) {
try {
LOGGER.log(
Expand Down