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 

https://github.com/jenkinsci/workflow-cps-global-lib-plugin

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)?

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/986a6368-c690-4751-a06a-2d5e2dffb4a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to