Skip to content
Permalink
Browse files

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

Prevents multiple FingerprintActions.

(cherry picked from commit be7a97e)

Conflicts:
	changelog.html
	core/src/main/java/hudson/tasks/Fingerprinter.java
	test/src/test/java/hudson/tasks/FingerprinterTest.java
  • Loading branch information
Stefan Wolf authored and olivergondza committed Feb 26, 2014
1 parent f768fb7 commit 1c847ccb5cdd92d36cc9344482247d6d86cff7df
@@ -133,7 +133,12 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
record(build, listener, record, expandedArtifacts);
}

build.getActions().add(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,18 +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.Hudson;
import hudson.model.Result;
import hudson.model.*;
import hudson.util.RunList;
import java.io.File;

@@ -44,10 +41,14 @@
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 org.junit.Assume;

import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
@@ -109,6 +110,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 1c847cc

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