Loop through BuildData as there can be more than one.

This commit is contained in:
Josh Barker 2017-08-08 20:00:12 +10:00
parent 46e1af798c
commit c8ebb2e283
1 changed files with 17 additions and 14 deletions

View File

@ -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;