I have a Jenkins pressure test to determine how many executors can be handled on my node:
// Jenkinsfile
int MAX_JOBS
static String jobTemplate(String name, int i) {
return """
job('$name') {
steps {
shell "/bin/bash /script/for/pressure/tests"
}
}
"""
}
def parallelledStages(int maxJobs) {
def stagesMap = [:]
for (int i = 0; i < maxJobs; i ++) {
def name = "test$i"
def stageStep = {
jobDsl scriptText: jobTemplate(name, i), sandbox: true
build name
}
stagesMap[name] = stageStep
}
return stagesMap
}
pipeline {
agent {
label "pressure_test"
}
stages {
stage("Init variables") {
steps {
script {
MAX_JOBS = 100
}
}
}
stage("Create and start jobs") {
steps {
script {
parallel parallelledStages(MAX_JOBS)
}
}
}
}
}
But in fact, when the pressure script finishs too fast (less than 30 seconds I think), some child jobs cannot start at all, and throws the following error:
Processing provided DSL script
java.util.ConcurrentModificationException
at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:719)
at java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:742)
at java.util.AbstractCollection.addAll(AbstractCollection.java:343)
at java.util.TreeSet.addAll(TreeSet.java:312)
at java.util.TreeSet.<init>(TreeSet.java:160)
at javaposse.jobdsl.plugin.actions.GeneratedObjectsRunAction.getModifiedObjects(GeneratedObjectsRunAction.java:47)
at javaposse.jobdsl.plugin.ExecuteDslScripts.perform(ExecuteDslScripts.java:364)
at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:112)
at sun.reflect.GeneratedMethodAccessor462.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:92)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:70)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
And the seed job will throw the error finally:
hudson.AbortException
at javaposse.jobdsl.plugin.ExecuteDslScripts.perform(ExecuteDslScripts.java:374)
at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:112)
Also: hudson.AbortException
at javaposse.jobdsl.plugin.ExecuteDslScripts.perform(ExecuteDslScripts.java:374)
at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:112)
Caused: java.lang.reflect.InvocationTargetException
Also: hudson.AbortException
at javaposse.jobdsl.plugin.ExecuteDslScripts.perform(ExecuteDslScripts.java:374)
at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:112)
Caused: java.lang.reflect.InvocationTargetException
Also: hudson.AbortException
at javaposse.jobdsl.plugin.ExecuteDslScripts.perform(ExecuteDslScripts.java:374)
at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:112)
Caused: java.lang.reflect.InvocationTargetException
Caused: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor462.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:92)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:70)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE
So just wondering:
- Is there something wrong in the `parallel` operator? Maybe some HashMap should be locked?
- How can I deal with this issue?