Skip to content

Commit

Permalink
Merge pull request #220 from jenkinsci/duplicate-scm
Browse files Browse the repository at this point in the history
Do not add a new action if already attached by a parallel step
  • Loading branch information
uhafner authored Jan 31, 2021
2 parents fc0ff48 + 62cb2f0 commit 33f0a06
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<url>https://github.com/jenkinsci/git-forensics-plugin</url>

<properties>
<revision>0.10.0</revision>
<revision>0.9.1</revision>
<changelist>-SNAPSHOT</changelist>

<module.name>${project.groupId}.git.forensics</module.name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GitCommitsRecord> 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 + "'",
Expand Down

0 comments on commit 33f0a06

Please sign in to comment.