Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: instanceof for library classes is false in template and other steps #279

Closed
steven-terrana opened this issue May 31, 2022 · 0 comments · Fixed by #282
Closed

[Bug]: instanceof for library classes is false in template and other steps #279

steven-terrana opened this issue May 31, 2022 · 0 comments · Fixed by #282
Assignees
Labels
bug Something isn't working

Comments

@steven-terrana
Copy link

steven-terrana commented May 31, 2022

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(). During start(), the Pipeline Template is compiled by a CpsGroovyShell created by a CpsGroovyShellFactory within CpsFlowExecution.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 running parseScript(), which follows the same process as above to create the StepWrapperScript - resulting in each step having its own classloader. This happens within StepWrapperFactory.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 various GroovyShellDecorator extensions (PipelineTemplateCompiler and StepWrapperShellDecorator) and that CompilerConfiguration is actually stored on the GroovyClassLoader.

Steps to Reproduce

create a library with a class:

class Build implements serializable{}

create a step to instantiate a Build object:

// createBuild.groovy
import Build
Build call(){
  return new Build()
}

create another step to check instanceof:

// checkBuild.groovy
import Build
void call(def b){
  println b instanceof Build // should be true, but is false
}

pipeline template:

def b = createBuild()
checkBuild(b)
@steven-terrana steven-terrana added the bug Something isn't working label May 31, 2022
@steven-terrana steven-terrana self-assigned this May 31, 2022
@jenkinsci jenkinsci deleted a comment from cokieffebah Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant