I'm having a Jenkins pipeline that does both build and deploy tasks in a scripted pipeline. The pipeline is maintained in a central repository. For each deployment stage, it will wait for the user input and the wait time can be up to several days. During the waiting period, if the pipeline script got changed, I want the latest script to be loaded after the deployment approval (user input).
The first load step of the script is working fine and when I try to load again, I'm getting an error below. It appears that the GroovyClassLoader is throwing this error.
I tried to remove the loadedScripts via currentBuild.rawBuild.getExecution().loadedScripts but that didn't help. Is there a way to achieve my use-case of reloading the script on every stage? Any pointers would be helpful.
java.lang.LinkageError: loader org.jenkinsci.plugins.workflow.cps.CpsGroovyShell$CleanGroovyClassLoader @8d141543 attempted duplicate class definition for Script1. (Script1 is in unnamed module of loader org.jenkinsci.plugins.workflow.cps.CpsGroovyShell$CleanGroovyClassLoader
// pipeline.groovy
def config
node('agent') {
stage('build') {
config = loadScripts()
echo 'perform some tasks'
}
stage('deploy-dev') {
input message: 'approve'
config = loadScripts()
echo 'perform some tasks'
}
stage('deploy-sit') {
input message: 'approve'
config = loadScripts()
echo 'perform some tasks'
}
}
def loadScripts() {
checkout scm
config = load 'somepath/external.groovy'
return config
}
// somepath/external.groovy
class JobConfig {
def someDataVar1
def someDataVar2
}
def sayHello() {
println 'hello'
}
return this
