Skip to content
Permalink
Browse files

[FIXED JENKINS-17606] Reuse existing fingerprint action if present.

Prevents multiple FingerprintActions.
  • Loading branch information
Stefan Wolf
Stefan Wolf committed Feb 4, 2014
1 parent 931d296 commit be7a97ee32b57dcb27b8fd6c908ebbe451220902
@@ -82,6 +82,9 @@
<li class=bug>
Wrong log message for out-of-order build record repair.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-20730">issue 20730</a>)
<li class=bug>
Existing Fingerprint Action is reused and not added a second time.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-17606">issue 19832</a>)
</ul>
</div><!--=TRUNK-END=-->

@@ -132,7 +132,12 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
record(build, listener, record, expandedArtifacts);
}

build.addAction(new FingerprintAction(build,record));
FingerprintAction fingerprintAction = build.getAction(FingerprintAction.class);
if (fingerprintAction != null) {
fingerprintAction.add(record);
} else {
build.addAction(new FingerprintAction(build,record));
}

if (enableFingerprintsInDependencyGraph) {
Jenkins.getInstance().rebuildDependencyGraphAsync();
@@ -24,17 +24,15 @@

package hudson.tasks;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import hudson.Launcher;
import hudson.Util;
import hudson.XmlFile;
import hudson.matrix.Axis;
import hudson.matrix.AxisList;
import hudson.matrix.MatrixProject;
import hudson.model.AbstractProject;
import hudson.model.Fingerprint;
import hudson.model.FingerprintCleanupThread;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.model.*;
import hudson.util.RunList;
import java.io.File;

@@ -43,10 +41,13 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;

import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.*;

import hudson.util.StreamTaskListener;
import jenkins.model.Jenkins;
import org.hamcrest.Matchers;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
@@ -111,6 +112,26 @@ public static void setUp() throws Exception {
assertTrue(downstreamProjects.contains(downstream));
}

private static class FingerprintAddingBuilder extends Builder {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
build.addAction(new Fingerprinter.FingerprintAction(build, ImmutableMap.of(singleFiles2[0], "fakefingerprint")));
return true;
}
}

@Test public void presentFingerprintActionIsReused() throws Exception {
FreeStyleProject project = createFreeStyleProjectWithFingerprints(singleContents, singleFiles);
project.getBuildersList().add(new FingerprintAddingBuilder());

FreeStyleBuild build = j.buildAndAssertSuccess(project);

assertThat(build.getActions(Fingerprinter.FingerprintAction.class), hasSize(1));

Fingerprinter.FingerprintAction action = build.getAction(Fingerprinter.FingerprintAction.class);
assertEquals(action.getRecords().keySet(), ImmutableSet.of(singleFiles2[0], singleFiles[0]));
}

@Test public void multipleUpstreamDependencies() throws Exception {
FreeStyleProject upstream = createFreeStyleProjectWithFingerprints(singleContents, singleFiles);
FreeStyleProject upstream2 = createFreeStyleProjectWithFingerprints(singleContents2, singleFiles2);

0 comments on commit be7a97e

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