Best way to get named parameter in a shared library function

1,118 views
Skip to first unread message

red 888

unread,
Aug 25, 2017, 3:59:12 PM8/25/17
to Jenkins Users
I have this in my shared library in /vars/myLib.groovy: 

def call(Map args) {

    one
= args.one
    two
= args.two
    three
= args.three

    somePlugin
(
        someParam
: one,
        otherParam
: two,
        anotherParam
: three
   
)

}

Then in my jenkinsfile I call it like this:
myLib(
    one
: 'sdfsdf',
    two
: 'ldskfjsdjf',
    three
: 'snfeknfsi'
)

This works great, but I was wondering if there is a better way to get named parameters or maybe there is a feature of the DSL I could leverage for something like this?

David Karr

unread,
Aug 25, 2017, 4:49:21 PM8/25/17
to Jenkins Users
You can simplify it somewhat by removing the intermediate variables:

def call(Map args) {
somePlugin(
someParam: args.one,
otherParam: args.two,
anotherParam: args.three
)
}

>
> --
> 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-use...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/3292a5e4-6ac9-4876-8da1-3dbd963bb9a3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages