Method names for getters/setters in pipeline shared libraries

63 views
Skip to first unread message

red 888

unread,
Aug 25, 2017, 1:33:26 PM8/25/17
to Jenkins Users
Im not sure if this is a groovy thing or a jenkins shared library DSL thing but I don't understand how this automatic getter setter stuff works.

I have this shared lib:
/vars/myFunc.groovy

I have this in it:
def getDerp() { return something }
def getHerp() { return something }

Now in my jenkinsfile I can reference it like this:
echo myFunc.derp
echo myFunc
.herp

But I tried naming my methods like this:
def getMyDerp() { return something }
def getMyHerp() { return something }

Now in my jenkinsfile I tried to do this:
echo myFunc.myderp
echo myFunc
.myherp

But that didn't work.

I'm just curious how this works and if its possible to do method names like getExtraHumps.


David Karr

unread,
Aug 25, 2017, 1:54:38 PM8/25/17
to Jenkins Users
You likely need to reference "myFunc.myDerp" instead.
> --
> 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/96c6a471-a94c-4fc8-b3a8-d9ea95f26be4%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

red 888

unread,
Aug 25, 2017, 2:46:00 PM8/25/17
to Jenkins Users
Yup "myFunc.myDerp" works! So is this a groovy thing or is this part of the jenkins DSL? I tried googling, but not sure what this language feature is called.

Baptiste Mathus

unread,
Aug 28, 2017, 2:42:17 PM8/28/17
to jenkins...@googlegroups.com
I'd say you're trying to use JavaBean on something that's not.
Also, see my previous answer earlier, it somehow smells a bit too programmatic. Ideally try not do only *very* basic programming in Pipeline, do like most if not all magical/nice Groovy features don't exist. 


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/6a901e11-309c-4cba-b3a9-1f3ef274280f%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages