Reputation: 1770
I am using Jenkins 2.6 on Red Hat Linux. I want to use the following in my Jenkinsfile, but when I try, Jenkins complains bitterly. (It seems only to dislike the syntax on left-hand side of the = operator.):
def (a, b) = [6, 7]
It doesn't like Multiple Assignments it seems, yet Groovy 1.6 and later apparently support them, as per this post:
http://mrhaki.blogspot.co.uk/2009/09/groovy-goodness-multiple-assignments.html
I want to do this so that when I call a method that returns [6, 7] I can call it like this:
def (a, b) = mymethod()
def mymethod()
{
return [6, 7]
}
Can anyone tell me whether this should work in Jenkins and if so in which version of Jenkins? Or is it an unsupported feature? Or a bug?
Thanks
Upvotes: 8
Views: 4520
Reputation: 20467
As explained here, Pipeline "scripts" are not simple Groovy scripts, they are heavily transformed before running, some parts on master, some parts on slaves, with their state (variable values) serialized and passed to the next step. As such, every Groovy feature is not supported.
I wish it was made more clear in Jenkins docs & presentations (that's why I find myself repeating the paragraph above... there is much confusion about this). Pipeline is so simple it seems magic... well, it kinda is ;)
It seems multiple assignments are not supported indeed. I only found this reference to confirm it: this example of a commit where the author changes his code from multiple assignments to simple ones because of that limitation.
Probably a good idea to ask for it on the mailing list as suggested by @rjohnston.
Upvotes: 4
Reputation: 7363
It should be available (and indeed it works from the Script Console) however it looks like whatever is necessary to make it work from a pipeline script hasn't been done.
The dev mailing list (https://groups.google.com/forum/#!forum/jenkinsci-dev) may be able to tell you if this is a bug or just an unsupported feature!
Upvotes: 0