pipeline groovy - can somebody please explain why variable value passing is working like this?

104 views
Skip to first unread message

Jonathan Hodgson

unread,
Nov 13, 2016, 1:05:14 PM11/13/16
to Jenkins Users
Ok, so having got my script working, I decided to move part of it into a shared library as per the section marked 

Define more structured DSL

here 


But I'm getting what to me seems like very odd behaviour with the variables.

My primary jenkins code (on the server in the job configuration, not a jenkinsfile in this case), looks like this (after cutting it down to the minimum to test this phenomemon)

@Library('mylibrary')


echo buildparam_project
.getClass().name
echo buildparam_project
def check = buildparam_project

utils = new gforce.utigforce.patchreader()


WpfCheckoutAndBuild {
    project
= "${check} Project is ${buildparam_project}"
}

buildparam_project is a build parameter

meanwhile, the file vars/WpfCheckoutAndBuild.groovy looks like this

def call(body) {
   
// evaluate the body block, and collect configuration into the object
   
def buildparam = [:]
    body
.resolveStrategy = Closure.DELEGATE_FIRST
    body
.delegate = buildparam
    body
()


    echo buildparam
.project
}


The output I see, is

[Pipeline] echo java.lang.String
[Pipeline] echo MyProject
[Pipeline] echo MyProject Project is null
[Pipeline] End of Pipeline Finished: SUCCESS

So buildparam_project can't be passed directly, I have to assign it to another variable first?

I assume this is something going on under the hood that I don't know about, Groovy can be very odd and Groovy under CPS considerably more so.

Could somebody explain it, and ideally give me a solution that doesn't require me to create copies of every build parameter (I'll do it if I have to, but it's messy)?

Thomas Keller

unread,
Nov 14, 2016, 5:25:12 AM11/14/16
to Jenkins Users
/sub

Jonathan Hodgson

unread,
Nov 14, 2016, 6:15:16 AM11/14/16
to Jenkins Users
I'm sorry, but am I supposed to know what that means?

On Monday, November 14, 2016 at 10:25:12 AM UTC, Thomas Keller wrote:
/sub

Lee Meador

unread,
Nov 15, 2016, 11:08:31 AM11/15/16
to jenkins...@googlegroups.com
I think he is saying to put the path part preceeding the file name inside the parentheses on the @Library annotation

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/d1b04553-3549-4312-b71f-680a8183e312%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-- Lee Meador
Sent from gmail. My real email address is lee AT leemeador.com

Thomas Keller

unread,
Nov 18, 2016, 1:52:51 PM11/18/16
to jenkins...@googlegroups.com
I'm just interested in this thread, so I'm subscribing by answering. Sorry for the confusion :)
--
Sent by my Droid

James Jermany

unread,
May 1, 2017, 3:31:05 PM5/1/17
to Jenkins Users
Did you every find a solution or come to understand why its like this?
Reply all
Reply to author
Forward
0 new messages