From c8ebb2e2833fcae092f56f080a9e892c0f551d8d Mon Sep 17 00:00:00 2001 From: Josh Barker Date: Tue, 8 Aug 2017 20:00:12 +1000 Subject: [PATCH] Loop through BuildData as there can be more than one. --- .../gitlabjenkins/util/BuildUtil.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/dabsquared/gitlabjenkins/util/BuildUtil.java b/src/main/java/com/dabsquared/gitlabjenkins/util/BuildUtil.java index f42e44c..5d9ecb6 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/util/BuildUtil.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/util/BuildUtil.java @@ -12,12 +12,13 @@ import hudson.plugins.git.util.MergeRecord; public class BuildUtil { public static Run getBuildByBranch(Job project, String branchName) { for (Run build : project.getBuilds()) { - BuildData data = build.getAction(BuildData.class); MergeRecord merge = build.getAction(MergeRecord.class); - if (hasLastBuild(data) && isNoMergeBuild(data, merge)) { - for (Branch branch : data.lastBuild.getRevision().getBranches()) { - if (branch.getName().endsWith("/" + branchName)) { - return build; + for(BuildData data : build.getActions(BuildData.class)) { + if (hasLastBuild(data) && isNoMergeBuild(data, merge)) { + for (Branch branch : data.lastBuild.getRevision().getBranches()) { + if (branch.getName().endsWith("/" + branchName)) { + return build; + } } } } @@ -27,10 +28,11 @@ public class BuildUtil { public static Run getBuildBySHA1WithoutMergeBuilds(Job project, String sha1) { for (Run build : project.getBuilds()) { - BuildData data = build.getAction(BuildData.class); MergeRecord merge = build.getAction(MergeRecord.class); - if (hasLastBuild(data) && isNoMergeBuild(data, merge) && data.lastBuild.isFor(sha1)) { - return build; + for(BuildData data : build.getActions(BuildData.class)) { + if (hasLastBuild(data) && isNoMergeBuild(data, merge) && data.lastBuild.isFor(sha1)) { + return build; + } } } return null; @@ -38,12 +40,13 @@ public class BuildUtil { public static Run getBuildBySHA1IncludingMergeBuilds(Job project, String sha1) { for (Run build : project.getBuilds()) { - BuildData data = build.getAction(BuildData.class); - if (data != null - && data.lastBuild != null - && data.lastBuild.getMarked() != null - && data.lastBuild.getMarked().getSha1String().equals(sha1)) { - return build; + for(BuildData data : build.getActions(BuildData.class)) { + if (data != null + && data.lastBuild != null + && data.lastBuild.getMarked() != null + && data.lastBuild.getMarked().getSha1String().equals(sha1)) { + return build; + } } } return null;