diff --git a/plugin/pom.xml b/plugin/pom.xml index 7902c3a6..9237af72 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -18,7 +18,7 @@ https://github.com/jenkinsci/git-forensics-plugin - 0.10.0 + 0.9.1 -SNAPSHOT ${project.groupId}.git.forensics diff --git a/plugin/src/main/java/io/jenkins/plugins/forensics/git/reference/GitCheckoutListener.java b/plugin/src/main/java/io/jenkins/plugins/forensics/git/reference/GitCheckoutListener.java index dff81f90..5985da1f 100644 --- a/plugin/src/main/java/io/jenkins/plugins/forensics/git/reference/GitCheckoutListener.java +++ b/plugin/src/main/java/io/jenkins/plugins/forensics/git/reference/GitCheckoutListener.java @@ -80,7 +80,9 @@ private void recordNewCommits(final Run build, final GitRepositoryValidato String latestRecordedCommit = getLatestRecordedCommit(build, id, logger); GitCommitsRecord commitsRecord = recordNewCommits(build, gitRepository, logger, latestRecordedCommit); - build.addAction(commitsRecord); + if (!hasRecordForScm(build, id)) { // In case a parallel step has added the same result in the meanwhile + build.addAction(commitsRecord); + } } private String getLatestRecordedCommit(final Run build, final String scmKey, final FilteredLog logger) { diff --git a/plugin/src/test/java/io/jenkins/plugins/forensics/git/reference/GitCheckoutListenerITest.java b/plugin/src/test/java/io/jenkins/plugins/forensics/git/reference/GitCheckoutListenerITest.java index 8d66f782..c8ed48f8 100644 --- a/plugin/src/test/java/io/jenkins/plugins/forensics/git/reference/GitCheckoutListenerITest.java +++ b/plugin/src/test/java/io/jenkins/plugins/forensics/git/reference/GitCheckoutListenerITest.java @@ -136,6 +136,30 @@ public void shouldDecorateSeveralRepositories() { verifyAction(actions.get(1), GIT_FORENSICS_URL); } + /** + * Creates a pipeline that checks out the same repository twice. + */ + @Test + public void shouldSkipDuplicateRepositories() { + WorkflowJob job = createPipeline(); + job.setDefinition(asStage( + "checkout([$class: 'GitSCM', " + + "branches: [[name: 'a6d0ef09ab3c418e370449a884da99b8190ae950' ]],\n" + + "userRemoteConfigs: [[url: '" + FORENSICS_API_URL + "']],\n" + + "extensions: [[$class: 'RelativeTargetDirectory', \n" + + " relativeTargetDir: 'forensics-api']]])", + "checkout([$class: 'GitSCM', " + + "branches: [[name: 'a6d0ef09ab3c418e370449a884da99b8190ae950' ]],\n" + + "userRemoteConfigs: [[url: '" + FORENSICS_API_URL + "']],\n" + + "extensions: [[$class: 'RelativeTargetDirectory', \n" + + " relativeTargetDir: 'forensics-api']]])")); + + List actions = buildSuccessfully(job).getActions(GitCommitsRecord.class); + assertThat(actions).hasSize(1); + + verifyAction(actions.get(0), FORENSICS_API_URL); + } + private void verifyAction(final GitCommitsRecord record, final String repository) { assertThat(record.getInfoMessages()) .contains("Recording commits of 'git " + repository + "'",