Jenkins shared library for pipelines “No such property”

1,525 views
Skip to first unread message

red 888

unread,
Aug 25, 2017, 11:08:25 AM8/25/17
to Jenkins Users

Im trying to wrap my head around shared libraries (with descriptive not scripted pipelines) and I'm not sure how I should be doing this.

Right now I have this in my jenkinsfile:

def Storeinvar = powershell (
    script: '$PSVersionTable.PSVersion.major',
    returnStdout: true
)

So I'm shelling out, running some command, and storing the result of that command in a var.

I want to put that in a shared library and call it anywhere in my jenkinsfile.

I created a file in my library: /var/myTest.groovy I put this in it to test:

def methA(body) {
     return 'FROM LIBRARY'
}
def methB(body) {
     return 'FROM LIBRARY'
}

In my jenkinsfile i call them like this:

echo gitInfo.methA()
echo gitInfo.methB()

But i get this error:

groovy.lang.MissingPropertyException: No such property: myTest for class: groovy.lang.Binding

Mark Waite

unread,
Aug 25, 2017, 11:14:30 AM8/25/17
to Jenkins Users
Maybe you need a "return this" at the end of the groovy file (as in https://github.com/docker/jenkins-pipeline-scripts/blob/master/src/com/docker/utilities/AWSSync.groovy)?

--
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/cbd9d243-ee34-4cd4-89b8-8def41fdfa77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

red 888

unread,
Aug 25, 2017, 12:26:23 PM8/25/17
to Jenkins Users
This is working for me now, I think the issue was that my groovy file under /var/ was not camel case so it wasn't finding it (locally it was camel case but my source control didn't pick up the rename because it used to be name MyTest.groovy).
Reply all
Reply to author
Forward
0 new messages