Skip to content

Commit

Permalink
Fix concurrent modification exception in ExecuteDslScripts (#1253)
Browse files Browse the repository at this point in the history
* Fix concurrent modification exception when removing multiple seed job references.

* JENKINS-69064: Fix concurrent modification exception when removing multiple seed job references.

Co-authored-by: giles.taylor <giles.meddows-taylor@man-es.com>
  • Loading branch information
gtaylor1981 and giles.taylor authored Oct 3, 2022
1 parent 54ae88a commit b735fa6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private Set<String> updateTemplates(Job seedJob, TaskListener listener,
Collection<SeedReference> seedJobReferences = descriptor.getTemplateJobMap().get(templateName);
Collection<SeedReference> matching = Collections2.filter(seedJobReferences, new SeedNamePredicate(seedJobName));
if (!matching.isEmpty()) {
seedJobReferences.removeAll(matching);
seedJobReferences.removeAll(Sets.newHashSet(matching));
descriptorMutated = true;
}
}
Expand All @@ -432,7 +432,7 @@ private Set<String> updateTemplates(Job seedJob, TaskListener listener,
} else {
if (matching.size() > 1) {
// Not sure how there could be more one, throw it all away and start over
seedJobReferences.removeAll(matching);
seedJobReferences.removeAll(Sets.newHashSet(matching));
}
seedJobReferences.add(new SeedReference(templateName, seedJobName, digest));
descriptorMutated = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,24 @@ folder('folder-a/folder-b') {
jenkinsRule.instance.getDescriptorByType(DescriptorImpl).generatedJobMap.size() == 0
}
def "JENKINS-69064 Deleted jobs with different seeds but same templates are removed from GeneratedJobMap"() {
setup:
FreeStyleProject seedJob = jenkinsRule.createFreeStyleProject('seed')
FreeStyleProject seedJob2 = jenkinsRule.createFreeStyleProject('seed2')
jenkinsRule.createFreeStyleProject('template')
runBuild(seedJob, new ExecuteDslScripts('job("test-job") {\n using("template")\n}'))
runBuild(seedJob2, new ExecuteDslScripts('job("test-job-2") {\n using("template")\n}'))
when:
ExecuteDslScripts builder = new ExecuteDslScripts('// do nothing')
builder.removedJobAction = RemovedJobAction.DELETE
runBuild(seedJob, builder)
runBuild(seedJob2, builder)
then:
jenkinsRule.instance.getDescriptorByType(DescriptorImpl).generatedJobMap.size() == 0
}
def "Manually deleted job is removed from GeneratedJobMap"() {
setup:
FreeStyleProject seedJob = jenkinsRule.createFreeStyleProject('seed')
Expand Down

0 comments on commit b735fa6

Please sign in to comment.