[Bug]: instanceof
for library classes is false
in template and other steps
#279
Labels
bug
Something isn't working
Jenkins Version
LTS
JTE Version
2.3
Bug Description
Instantiations of library provided classes are not recognized outside of the step where they were created.
Root Cause
After some digging I've identified the root cause of this problem.
The Pipeline Template, and each StepWrapperScript, are compiled with different classloaders.
Pipeline execution begins via
CpsFlowExecution.start()
. Duringstart()
, the Pipeline Template is compiled by aCpsGroovyShell
created by aCpsGroovyShellFactory
withinCpsFlowExecution.parseScript()
which results in the normal classloader that's typically used in a Jenkins pipeline. See workflow-cps/doc/classloader.md for more info there.Each JTE library step is compiled by creating individual mock
CpsFlowExecution
and runningparseScript()
, which follows the same process as above to create theStepWrapperScript
- resulting in each step having its own classloader. This happens withinStepWrapperFactory.prepareScript()
.So far, attempts at creating a common classloader shared by the Pipeline Template and each
StepWrapperScript
have failed - resulting in either compilation errors or serialization errors preventing rehydrating after a restart.The compilation errors are coming from the fact that the template and steps require a different
CompilerConfiguration
which we modify in variousGroovyShellDecorator
extensions (PipelineTemplateCompiler
andStepWrapperShellDecorator
) and thatCompilerConfiguration
is actually stored on theGroovyClassLoader
.Steps to Reproduce
create a library with a class:
create a step to instantiate a
Build
object:create another step to check
instanceof
:pipeline template:
The text was updated successfully, but these errors were encountered: