Interview Prep/Jenkins/Jenkinsfile syntax, Groovy & CPS errors

`org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.lang.GroovyObject invokeMethod java.lang.String java.lang.Object`

IntermediateTroubleshootingJenkinsfile syntax, Groovy & CPS errors
Answer

Likely causes → Sandbox blocks a dynamic method call, often from calling a method on an untyped object in an untrusted library, or a misspelled method name that Groovy resolves dynamically.

Diagnose → Look at the line in the stack trace; check In-process Script Approval for the pending signature.

Fix → Fix the typo or type the variable. Do not approve invokeMethod generically; it allows calling any method. Move logic to a trusted library if it legitimately needs it.

Prevent → Unit test library code with JenkinsPipelineUnit and run test pipelines in the sandbox.

All Jenkins questions Roadmap: Jenkins

More on Jenkinsfile syntax, Groovy & CPS errors