In my Jenkins pipeline, I'm storing a Map to pass into the checkout stage of the pipeline. I did not have issue with this code previously, but now I've modified it for parallel stages, it seems to intermittently fail with the error:
dir – java.io.NotSerializableException: .codehaus.groovy.runtime.NullObject
What is stumping me is the error is extremely intermittent. For instance, only one out of 10 jobs will have this error, and in that failed job, each job has 10 parallel stages, and only 1 stage will fail with this error.
I've renamed and removed some code, but below is an example of how the pipeline has been structured.
def map = MAP_PARAM ? MAP_PARAM.tokenize("\n").collectEntries {
it.tokenize("=").with {
it[1] ? [(it[0]):it[1]] : [:]
}
} : [:]
...
pipeline {
agent none
options { skipDefaultCheckout() }
stages {
stage('Create stages') {
steps {
script {
...
// Create parallel jobs
for (b in branches) {
def branch = "${b}"
branches[branch] = {
podTemplate(yaml: ..., cloud: ...) {
node(...) {
container(...) {
stage('Checkout') {
checkout(map)
}
stage('Build') {
build(...)
}
}
}
}
}
}
}
}
}
stage('Run Stages') {
steps {
script {
parallel(branches)
}
}
}