Skip to content
Permalink
Browse files

Merge pull request #372 from abayer/jenkins-29326

[JENKINS-29326] Don't add duplicate BuildData
  • Loading branch information...
abayer committed Dec 16, 2015
2 parents 056e522 + 0e7b7a5 commit 959bca0d9f92b31ed83c991bdbd6c24c2463daa3
@@ -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);
}
@@ -1053,6 +1053,17 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas
retrieveChanges(build, git, listener);
Build revToBuild = determineRevisionToBuild(build, buildData, environment, git, listener);

// Track whether we're trying to add a duplicate BuildData, now that it's been updated with
// revision info for this build etc. The default assumption is that it's a duplicate.
boolean buildDataAlreadyPresent = build.getActions(BuildData.class).contains(buildData);

// If the BuildData is not already attached to this build, add it to the build and mark that
// it wasn't already present, so that we add the GitTagAction and changelog after the checkout
// finishes.
if (!buildDataAlreadyPresent) {
build.addAction(buildData);
}

environment.put(GIT_COMMIT, revToBuild.revision.getSha1String());
Branch branch = Iterables.getFirst(revToBuild.revision.getBranches(),null);
if (branch != null && branch.getName() != null) { // null for a detached HEAD
@@ -1068,16 +1079,19 @@ 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 (!buildDataAlreadyPresent) {
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) {
@@ -1,5 +1,6 @@
package hudson.plugins.git.util;

import com.google.common.base.Objects;
import hudson.model.Result;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.Revision;
@@ -91,6 +92,22 @@ 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
&& Objects.equal(otherBuild.revision, this.revision)
&& Objects.equal(otherBuild.marked, this.marked)) {
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 959bca0

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