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;