Mark Tickner
Mark Tickner

Reputation: 1053

Groovy named parameter causing ClassCastException

I have a Groovy script which is run in Jenkins. For context, I am using the SAML Plugin, and specifically using the SamlSecurityRealm constructor. This works fine.

However, to improve readability, I have attempted to used named parameters. The parameter binding, which is of type String, is causing the following exception:

java.lang.ClassCastException: java.lang.String cannot be cast to groovy.lang.Binding

My usage is like this:

binding = 'String value'

This syntax is working for all of the other parameters, and if I remove just this one named parameter, the script runs.

I am familiar with Java and Scala, but not so much with Groovy. binding does not seem to be a keyword, but I am assuming I need to escape it somehow? Wrapping it in single or double quotes, or backticks is also not working.

Upvotes: 0

Views: 596

Answers (1)

daggett
daggett

Reputation: 28564

if you are inside groovy Script then binding = XYZ tries to call Script.setBinding(XYZ)

https://docs.groovy-lang.org/latest/html/api/groovy/lang/Script.html

unless you declare a variable binding like this:

def binding = XYZ

Upvotes: 1

Related Questions