jenkinsci / templating-engine-plugin

create tool-agnostic, templated pipelines to be shared by multiple teams
https://jenkinsci.github.io/templating-engine-plugin/latest/
Apache License 2.0
171 stars 58 forks source link

[Bug]: Refusing to marshal org.codehaus.groovy.runtime.GStringImpl for security reasons; #311

Closed brosmar closed 1 year ago

brosmar commented 1 year ago

Jenkins Version

CloudBees CI Client Controller 2.375.1.1-rolling

JTE Version

2.5.2

Bug Description

I am migrating form Jenkins Templating Engine 1.x to 2.5.2. I have made the necessary code changes. All global variables where now accessed using the "globals" object. In our Test Jenkins I am testing the migrated sources.

During a Complex pipeline the Job terminates with the exception:

hudson.remoting.ProxyException: java.lang.UnsupportedOperationException: Refusing to marshal org.codehaus.groovy.runtime.GStringImpl for security reasons; see https://www.jenkins.io/redirect/class-filter/

The complete log starting with the problematic Parts where the exception is thrown you can find in the Relevant log output below.

The library source that is executed in the moment of the exception is a during a @BeforeStep. But a similar error was thrown during a normal Step. A similar Issue was already raised: https://github.com/jenkinsci/templating-engine-plugin/issues/207. I tried the mentioned "Text".toString() workaround with no success.

The exception occurs in the following beforeStep() function. "trace 1" is written in the output "trace 2" not. This is the function in progress:

Code starts here: -------------------------------------- `@BeforeStep void beforeStep() { println """ +++ called library: $hookContext.library, function: $hookContext.step +++ """ if (hookContext.step.equals("check_pr") || hookContext.library.equals("git_scm")) { //vars not set println """do nothing because: hookContext.step.equals("check_pr") || hookContext.library.equals("git_scm")

+++ return library: $hookContext.library, function: $hookContext.step +++ """ return } println "trace 1" env.stepFailed = "false".toString() println "trace 2" //TODO: move to initialize env.githubInit = (env.githubInit) ? true : false

if (!env.githubInit.toBoolean()) {
    if (env.GIT_REPO) {
        println "init github informations for Github Status notifications"
        def regex = /(https:\/\/|git@)github\.name\.de[:\/](.*\/.*)\.git/

        if (env.GIT_REPO.matches(regex)) {
            def m = env.GIT_REPO =~ regex
            env.nameSpaceAndReponame = m[0][2] //dev/reponame
            env.repoUrl = "https://git-server-instance/api/v3/repos/" + nameSpaceAndReponame
            env.githubInit = true
            printDebug("beforeStep","nameSpaceAndReponame: " + nameSpaceAndReponame +  " repoUrl: " + repoUrl)
        }
        env.githubInit = true
    }
}

println """ +++ return library: $hookContext.library, function: $hookContext.step +++ """ }` Code ends here: -------------------------------------- (The conde annotation dose not work correctly)

Do you have an clue(glue) to fix this.

Thanks for your support Martin

Relevant log output

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
begin BeforeStep:
library: sonar_java_ds, function: lint, stepFailed: false
result: null
current: SUCCESS
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

[JTE][@BeforeStep - notify/02_notify_github.beforeStep]
[Pipeline] echo

+++
called library: sonar_java_ds, function: lint
+++

[Pipeline] echo
trace 1
[JTE][@AfterStep - notify/00_notify_start.AfterStep]
[Pipeline] echo

-------------------------------------------------------------------------------------------------
begin AfterStep:
library: sonar_java_ds, function: lint, stepFailed: false
result: null
current: SUCCESS
-------------------------------------------------------------------------------------------------

[JTE][@AfterStep - notify/01_notify_slack.AfterStep]
[Pipeline] echo

---
called library: sonar_java_ds, function: lint
---

[Pipeline] echo
[debug] AfterStep: currentBuildResult: null
[Pipeline] echo
[debug] notifySlack: entering
[Pipeline] echo
[debug] notifySlack: return early: nullCheck: true notifySlack: false slackChannel:undefined-slackChannel slackTeamDomain:undefined-slackTeamDomain slackCredentialToken: undefined-slackTokenCredentialId
[Pipeline] echo

---
return library: sonar_java_ds, function: lint
---

[JTE][@AfterStep - notify/02_notify_github.afterStep]
[Pipeline] echo

---
called library: sonar_java_ds, function: lint
---

[Pipeline] echo
[debug] sendPRRequest: nameSpaceAndReponame: dev/xentricmarketstack-api reponame: dev/xentricmarketstack-api
[Pipeline] echo
[debug] sendPRRequest: gitHubCondition: true
[Pipeline] echo
[debug] sendPRRequest: sendPRRequest for function: lint success: failure
[Pipeline] withCredentials
Masking supported pattern matches of $TOKEN
[Pipeline] {
[Pipeline] sh
Warning: A secret was passed to "sh" using Groovy String interpolation, which is insecure.
         Affected argument(s) used the following variable(s): [TOKEN]
         See https://jenkins.io/redirect/groovy-string-interpolation for details.
+ curl --proxy http://proxy-host:port https://git-server-instance/api/v3/repos/dev/xentricmarketstack-api/statuses/759df3acd2278601a302f112c9aff500c36064ef -H 'Authorization: token ****' -d '{"state": "failure",  "target_url": "https://jenkinsserver.de/job/MarketData-Simulation/job/XENTRIC-Simulation/job/XMS/job/API/job/build-api/job/develop/111/",  "description": "failure",  "function": "lint" }' -i -v
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] echo

---
return library: sonar_java_ds, function: lint
---

[JTE][@AfterStep - notify/99_notify_stop.AfterStep]
[Pipeline] echo

-------------------------------------------------------------------------------------------------
end AfterStep:
library: sonar_java_ds, function: lint, stepFailed: false
result: null
current: SUCCESS
-------------------------------------------------------------------------------------------------

[Pipeline] echo

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Exception during Step: lint processing
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Notify:
library: sonar_java_ds, function: lint, stepFailed: false
result: null
current: SUCCESS
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

[JTE][@Notify - notify/99_notify_stop.Notify]
[Pipeline] echo

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Exception during Step: lint processing
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Notify:
library: sonar_java_ds, function: lint, stepFailed: false
result: null
current: SUCCESS
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

[Pipeline] }
Lock released on resource [MarketData-Simulation/XENTRIC-Simulation/XMS/API/build-api/develop]
[Pipeline] // lock
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // withFolderProperties
[JTE][@Notify - notify/99_notify_stop.Notify]
[Pipeline] echo

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Exception during Step: null processing
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Notify:
library: null, function: null, stepFailed: false
result: null
current: SUCCESS
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

[Pipeline] End of Pipeline
hudson.remoting.ProxyException: java.lang.UnsupportedOperationException: Refusing to marshal org.codehaus.groovy.runtime.GStringImpl for security reasons; see https://www.jenkins.io/redirect/class-filter/
    at hudson.util.XStream2$BlacklistedTypesConverter.marshal(XStream2.java:583)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:44)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:87)
    at com.thoughtworks.xstream.converters.reflection.SerializableConverter$1.writeToStream(SerializableConverter.java:139)
    at com.thoughtworks.xstream.core.util.CustomObjectOutputStream.writeObjectOverride(CustomObjectOutputStream.java:87)
    at java.base/java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:341)
    at java.base/java.util.LinkedHashMap.internalWriteEntries(LinkedHashMap.java:333)
    at java.base/java.util.HashMap.writeObject(HashMap.java:1412)
    at java.base/jdk.internal.reflect.GeneratedMethodAccessor1091.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at com.thoughtworks.xstream.core.util.SerializationMembers.callWriteObject(SerializationMembers.java:154)
Caused: hudson.remoting.ProxyException: com.thoughtworks.xstream.converters.ConversionException: Failed calling method
---- Debugging information ----
message             : Failed calling method
cause-exception     : java.lang.UnsupportedOperationException
cause-message       : Refusing to marshal org.codehaus.groovy.runtime.GStringImpl for security reasons; see https://www.jenkins.io/redirect/class-filter/
method              : org.boozallen.plugins.jte.init.governance.config.dsl.PipelineConfigurationDsl$ConfigBlockMap.writeObject()
-------------------------------
    at com.thoughtworks.xstream.core.util.SerializationMembers.callWriteObject(SerializationMembers.java:161)
    at com.thoughtworks.xstream.converters.reflection.SerializableConverter.doMarshal(SerializableConverter.java:257)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:90)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
    at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:285)
    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:272)
Caused: hudson.remoting.ProxyException: java.lang.RuntimeException: Failed to serialize org.boozallen.plugins.jte.init.primitives.injectors.Keyword#value for class org.boozallen.plugins.jte.init.primitives.injectors.Keyword
    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:276)
    at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:243)
    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:174)
    at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:228)
    at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:165)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:44)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:87)
    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeBareItem(AbstractCollectionConverter.java:94)
    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeItem(AbstractCollectionConverter.java:66)
    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeCompleteItem(AbstractCollectionConverter.java:81)
    at com.thoughtworks.xstream.converters.collections.CollectionConverter.marshal(CollectionConverter.java:75)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
    at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:285)
    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:272)
Caused: hudson.remoting.ProxyException: java.lang.RuntimeException: Failed to serialize org.boozallen.plugins.jte.init.primitives.TemplatePrimitiveNamespace#primitives for class org.boozallen.plugins.jte.init.primitives.TemplatePrimitiveNamespace
    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:276)
    at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:243)
    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:174)
    at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:228)
    at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:165)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:44)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:87)
    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeBareItem(AbstractCollectionConverter.java:94)
    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeItem(AbstractCollectionConverter.java:66)
    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeCompleteItem(AbstractCollectionConverter.java:81)
    at com.thoughtworks.xstream.converters.collections.CollectionConverter.marshal(CollectionConverter.java:75)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
    at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:285)
    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:272)
Caused: hudson.remoting.ProxyException: java.lang.RuntimeException: Failed to serialize org.boozallen.plugins.jte.init.primitives.TemplatePrimitiveCollector#namespaces for class org.boozallen.plugins.jte.init.primitives.TemplatePrimitiveCollector
    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:276)
    at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:243)
    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:174)
    at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:228)
    at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:165)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:44)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:87)
    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeBareItem(AbstractCollectionConverter.java:94)
    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeItem(AbstractCollectionConverter.java:66)
    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeCompleteItem(AbstractCollectionConverter.java:81)
    at com.thoughtworks.xstream.converters.collections.CollectionConverter.marshal(CollectionConverter.java:75)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:83)
    at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:285)
    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:272)
Caused: hudson.remoting.ProxyException: java.lang.RuntimeException: Failed to serialize hudson.model.Actionable#actions for class org.jenkinsci.plugins.workflow.job.WorkflowRun
    at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:276)
    at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:243)
    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:174)
    at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:228)
    at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:165)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:59)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:44)
    at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:83)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:1266)
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:1255)
    at com.thoughtworks.xstream.XStream.toXML(XStream.java:1228)
    at hudson.XmlFile.write(XmlFile.java:213)
Caused: hudson.remoting.ProxyException: java.io.IOException: java.lang.RuntimeException: Failed to serialize hudson.model.Actionable#actions for class org.jenkinsci.plugins.workflow.job.WorkflowRun
    at hudson.XmlFile.write(XmlFile.java:220)
    at org.jenkinsci.plugins.workflow.support.PipelineIOUtils.writeByXStream(PipelineIOUtils.java:30)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.save(WorkflowRun.java:1244)
    at org.jenkinsci.plugins.workflow.cps.EnvActionImpl.setProperty(EnvActionImpl.java:132)
    at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:213)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:497)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.setProperty(DefaultInvoker.java:44)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawSet(PropertyAccessBlock.java:24)
Caused: hudson.remoting.ProxyException: java.lang.RuntimeException: java.io.IOException: java.lang.RuntimeException: Failed to serialize hudson.model.Actionable#actions for class org.jenkinsci.plugins.workflow.job.WorkflowRun
    at org.jenkinsci.plugins.workflow.cps.EnvActionImpl.setProperty(EnvActionImpl.java:134)
    at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:213)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:497)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.setProperty(DefaultInvoker.java:44)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawSet(PropertyAccessBlock.java:24)
    at JTE_notify_02_notify_github.beforeStep(JTE_notify_02_notify_github:68)
    at org.boozallen.plugins.jte.init.primitives.hooks.AnnotatedMethod.invoke(AnnotatedMethod.groovy:53)
    at org.boozallen.plugins.jte.init.primitives.hooks.Hooks.invoke(Hooks.groovy:60)
    at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2125)
    at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2110)
    at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2151)
    at org.boozallen.plugins.jte.init.primitives.hooks.Hooks.invoke(Hooks.groovy:58)
    at org.boozallen.plugins.jte.init.primitives.injectors.StepWrapperCPS.methodMissing(script1671638419843216937907.groovy:57)
    at WorkflowScript.run(WorkflowScript:10)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.set(PropertyishBlock.java:87)
    at com.cloudbees.groovy.cps.impl.AssignmentBlock$ContinuationImpl.assignAndDone(AssignmentBlock.java:70)
    at jdk.internal.reflect.GeneratedMethodAccessor1033.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:93)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:115)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:80)
    at jdk.internal.reflect.GeneratedMethodAccessor1026.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
Caused: hudson.remoting.ProxyException: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.RuntimeException: java.io.IOException: java.lang.RuntimeException: Failed to serialize hudson.model.Actionable#actions for class org.jenkinsci.plugins.workflow.job.WorkflowRun
    at org.boozallen.plugins.jte.init.primitives.hooks.AnnotatedMethod.invoke(AnnotatedMethod.groovy:55)
    at org.boozallen.plugins.jte.init.primitives.hooks.Hooks.invoke(Hooks.groovy:60)
    at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2125)
    at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2110)
    at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2151)
    at org.boozallen.plugins.jte.init.primitives.hooks.Hooks.invoke(Hooks.groovy:58)
    at org.boozallen.plugins.jte.init.primitives.injectors.StepWrapperCPS.methodMissing(script1671638419843216937907.groovy:57)
Caused: hudson.remoting.ProxyException: org.codehaus.groovy.runtime.InvokerInvocationException: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.RuntimeException: java.io.IOException: java.lang.RuntimeException: Failed to serialize hudson.model.Actionable#actions for class org.jenkinsci.plugins.workflow.job.WorkflowRun
    at org.boozallen.plugins.jte.init.primitives.injectors.StepWrapperCPS.methodMissing(script1671638419843216937907.groovy:62)
    at WorkflowScript.run(WorkflowScript:10)
    at ___cps.transform___(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:238)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.constructorCall(DefaultInvoker.java:25)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:99)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:85)
    at jdk.internal.reflect.GeneratedMethodAccessor1027.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.LocalVariableBlock$LocalVariable.get(LocalVariableBlock.java:39)
    at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
    at com.cloudbees.groovy.cps.impl.LocalVariableBlock.evalLValue(LocalVariableBlock.java:28)
    at com.cloudbees.groovy.cps.LValueBlock$BlockImpl.eval(LValueBlock.java:55)
    at com.cloudbees.groovy.cps.LValueBlock.eval(LValueBlock.java:16)
    at com.cloudbees.groovy.cps.Next.step(Next.java:83)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:158)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:152)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:152)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:187)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:420)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:95)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:330)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:294)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:30)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:70)
Caused: hudson.remoting.ProxyException: java.util.concurrent.ExecutionException: org.codehaus.groovy.runtime.InvokerInvocationException: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.RuntimeException: java.io.IOException: java.lang.RuntimeException: Failed to serialize hudson.model.Actionable#actions for class org.jenkinsci.plugins.workflow.job.WorkflowRun
    at org.jenkinsci.plugins.workflow.cps.CpsBodyExecution.get(CpsBodyExecution.java:303)
    at com.mig82.folders.step.FolderPropertiesStep$Execution.run(FolderPropertiesStep.java:55)
    at com.mig82.folders.step.FolderPropertiesStep$Execution.run(FolderPropertiesStep.java:37)
    at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
    at hudson.security.ACL.impersonate2(ACL.java:451)
    at hudson.security.ACL.impersonate(ACL.java:463)
    at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
[Checks API] No suitable checks publisher found.
Finished: FAILURE

Steps to Reproduce

I only have my complex test system. I have no small code fragment to reproduce it.

brosmar commented 1 year ago

Happy New Year to the template engine Team.

Is there something missing in my description? The Bug is still a problem for me. Is there a reason why it is not assigned.

brosmar commented 1 year ago

We Installed the new Plugin Version 2.5.3 and restarted the jenkins server. The job is still crashing. The callstack dump is 100% the same as stated above. No Line has changed.

brosmar commented 1 year ago

Sorry, the comment before is false. The job is still crashing at the same place but the callstack is different. Please see the attached dump file 2.5.3versionDump.txt .

`[Pipeline] End of Pipeline hudson.remoting.ProxyException: java.lang.UnsupportedOperationException: Refusing to marshal org.jenkinsci.plugins.docker.workflow.Docker$Image for security reasons; see https://www.jenkins.io/redirect/class-filter/

---- Debugging information ---- message : Failed calling method cause-exception : java.lang.UnsupportedOperationException cause-message : Refusing to marshal org.jenkinsci.plugins.docker.workflow.Docker$Image for security reasons; see https://www.jenkins.io/redirect/class-filter/ method : org.boozallen.plugins.jte.init.governance.config.dsl.PipelineConfigurationDsl$ConfigBlockMap.writeObject() -------------------------------`

jglick commented 1 year ago

Sounds like there are deeper structural problems with either this plugin or your attempted usage of it (or both).

brosmar commented 1 year ago

Do you have an Idea what could be the structural root cause? The Job is breaking in an Lifecycle Hooks lifecyclehook.txt. The last wiritten trace is "trace1" in line 63.

jglick commented 1 year ago

Sorry, no idea, I am not a maintainer and have little knowledge of this plugin.

brosmar commented 1 year ago

I reduced the error to a docker.image call and replaced it with shell commands. And now the pipeline works fine.

When running the following code:

        def cmd = "mvn -B -s settings.xml ${env.MAVEN_OPTIONS} sonar:sonar ${args.collect { "-D" + it }.join(' ')}".toString()
        //def cmd = "mvn -B -s settings.xml clean"
        println "running command: $cmd \ninside container: $globals.localBuildImage".toString();
        if (true) {   // when set to true the pipeline crashes if false all is ok
           docker.image(globals.localBuildImage).inside {
               sh cmd
           }
        } else {
            def containerId = sh (script: "docker run -d -it $globals.localBuildImage $cmd", returnStdout: true).trim()
            sh "docker wait $containerId"
            sh "docker container logs $containerId"
        }

The pipline creates the Dump: 2.5.3versionDump.txt

When i change the line

if (true) { // when set to true the pipeline crashes if false all is ok

to

if (false) { // when set to true the pipeline crashes if false all is ok

The pipeline works fine and dose not throw an exception.

Do you have an explanation for this workaround? Is there a problem with the templating engine or with the "docker-workflow" plugin. ( The old templating engine 1.x was working fine with the docker-wokflow plugin )

jglick commented 1 year ago

Is there a problem with the templating engine or with the "docker-workflow" plugin

Clearly the templating-engine plugin is at fault here, specifically something added to https://github.com/jenkinsci/templating-engine-plugin/blob/f73cae43a50c20387b697d8d376edd8dbf960fed/src/main/groovy/org/boozallen/plugins/jte/init/primitives/TemplatePrimitiveCollector.groovy#L51 whose purpose I can only speculate about.

That said, as an original author of docker-workflow, I do not recommend using the withDockerContainer step (for which docker.image(…).inside {…} is syntax sugar), or at least abandoning it at the first sign of trouble.

Anyway, based on the error here, another workaround might be to run the withDockerContainer step directly, without the docker DSL sugar.

brosmar commented 1 year ago

Do I understand correctly:

docker.image().inside() should not be used in the Jenkins Templating Engine script

The reason for that is the mentioned Line: "List<TemplatePrimitiveNamespace> namespaces = [] " But nobody is taking care of this since weeks.

Is the Jenkins Templating Engine dead?

steven-terrana commented 1 year ago

no, it's not.

@jglick contributed https://github.com/jenkinsci/templating-engine-plugin/pull/312 which was released in version 2.5.3

can you please try upgrading to see if this resolves your issue?

jglick commented 1 year ago

https://github.com/jenkinsci/templating-engine-plugin/issues/311#issuecomment-1376854543

steven-terrana commented 1 year ago

thanks @jglick,

@brosmar - i'd like to help but i'm unsure how to without being able to reproduce the bug.