Skip to content
Permalink
Browse files

[FIXED JENKINS-29326] Don't add duplicate BuildData.

Added equals methods to BuildData and Build, and check if we already
have an equivalent BuildData on a build before we add it, the git tag
action and changelog, so that we avoid duplicate records of all these things.
  • Loading branch information...
abayer committed Dec 10, 2015
1 parent f00f379 commit b4a4c7d63106ea1b7989d579f99e60ceef0271af
@@ -1038,7 +1038,7 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas

BuildData previousBuildData = getBuildData(build.getPreviousBuild()); // read only
BuildData buildData = copyBuildData(build.getPreviousBuild());
build.addAction(buildData);

if (VERBOSE && buildData.lastBuild != null) {
listener.getLogger().println("Last Built Revision: " + buildData.lastBuild.revision);
}
@@ -1068,16 +1068,20 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas

try {
checkoutCommand.execute();
} catch(GitLockFailedException e) {
} catch (GitLockFailedException e) {
// Rethrow IOException so the retry will be able to catch it
throw new IOException("Could not checkout " + revToBuild.revision.getSha1String(), e);
}

build.addAction(new GitTagAction(build, workspace, revToBuild.revision));
// Don't add the tag and changelog if we've already processed this BuildData before.
if (!build.getActions(BuildData.class).contains(buildData)) {
build.addAction(buildData);
build.addAction(new GitTagAction(build, workspace, revToBuild.revision));

if (changelogFile != null) {
computeChangeLog(git, revToBuild.revision, listener, previousBuildData, new FilePath(changelogFile),
new BuildChooserContextImpl(build.getParent(), build, environment));
if (changelogFile != null) {
computeChangeLog(git, revToBuild.revision, listener, previousBuildData, new FilePath(changelogFile),
new BuildChooserContextImpl(build.getParent(), build, environment));
}
}

for (GitSCMExtension ext : extensions) {
@@ -91,6 +91,21 @@ public Result getBuildResult() {
return "Build #" + hudsonBuildNumber + " of " + revision.toString();
}

@Override
public boolean equals(Object o) {
if (!(o instanceof Build)) {
return false;
} else {
Build otherBuild = (Build) o;
if (otherBuild.hudsonBuildNumber == this.hudsonBuildNumber
&& otherBuild.revision.equals(this.revision)) {
return true;
} else {
return false;
}
}
}

@Override
public Build clone() {
Build clone;
@@ -16,7 +16,6 @@
import java.util.*;

import static hudson.Util.fixNull;

/**
* Captures the Git related information for a build.
*
@@ -245,6 +244,23 @@ public String toString() {
",lastBuild="+lastBuild+"]";
}

@Override
public boolean equals(Object o) {
if (!(o instanceof BuildData)) {
return false;
} else {
BuildData otherBuildData = (BuildData) o;

if (otherBuildData.remoteUrls.equals(this.remoteUrls)
&& otherBuildData.buildsByBranchName.equals(this.buildsByBranchName)
&& otherBuildData.lastBuild.equals(this.lastBuild)) {
return true;
} else {
return false;
}
}
}

/**
* Remove branches from BuildData that have been seen in the past but do not exist anymore
* @param keepBranches all branches available in current repository state

0 comments on commit b4a4c7d

Please sign in to comment.
You can’t perform that action at this time.