Why does the jenkinsfile use a closure in this way?

33 views
Skip to first unread message

red 888

unread,
Oct 4, 2017, 5:12:44 PM10/4/17
to Jenkins Users

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.

Reply all
Reply to author
Forward
0 new messages