Why does the jenkinsfile use a closure in this way?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Why does the jenkinsfile use a closure in this way?

red 888

Its a command pattern to write jenkins pipeline code like this:

def call(body) {

    def config = [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = config
    body()

Im not sure how to word this simply, but this closure get implicitly imported and can be called by the file name of the .groovy file it lives in.

I call it like: MyClosher{myarg ='sdfsdf}

I not entirely sure what this is doing. Its doing call(body) and then assigning body as the delegate. so that means the closure i pass it is the delegate, but isn't that just the owner? wah me confused.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/82e5ff55-0ea9-4ca5-88d4-9b9fe7201ee5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.