Trouble using shared pipeline libraries

1,891 views
Skip to first unread message

Ramanathan Muthaiah

unread,
Dec 22, 2016, 4:28:38 AM12/22/16
to Jenkins Users
Am running Jenkins v2.3x with Pipeline plugin running at v2.x

In the repo root, I have a Jenkinsfile from which shared library is meant to be used.

repo_root /
                 |_____ Jenkinsfile
                 |
                 |_____ vars /
                                     |
                                     |____ buildUtils.groovy

Within the buildUtils.groovy, this is the code snippet:

#!groovy

def call(body) {

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

    node
('linux') {
        checkout scm
       
def url = "https://github.com/jenkinsci/${config.name}-plugin.git"
        echo
" == URL with repo name == "
        echo
"${url}"
   
}
}


With this setup in place, running Jenkins build job for this repo, fails with this error:

[Pipeline] End of Pipeline
java.lang.NoSuchMethodError: No such DSL method 'buildUtils' found among steps 

I have been scourging forums here, in SO, in Google but no real solutions seem to
be available (atleast, it seems to escape my eyes).

What's going wrong here ?

TIA,
/Ram

Torsten Reinhard

unread,
Dec 25, 2016, 5:32:56 AM12/25/16
to Jenkins Users
can you provide some more info, especially
* how does your Jenkisfile look like
* do you have global shared library configured or per folder?
* which version of the shared library do you adress? Is your script available in that version?
* do you have same script in the internal repo?

Regards, Torsten

Ramanathan Muthaiah

unread,
Dec 25, 2016, 8:33:45 AM12/25/16
to Jenkins Users
Here are some details but am not confident about my setup based on what you're asking.
Maybe, you can help me to clarify what am doing incorrectly.

* how does your Jenkisfile look like
[Ram] : Jenkinsfile content is:

buildUtils("git")
 
* do you have global shared library configured or per folder?
[Ram] : Looks like am missing some configuration here but fail to understand what is it from the plugin docs ?
 
* which version of the shared library do you adress? Is your script available in that version?
[Ram] : Am not sure if understood your question. Shared Groovy library plugin installed is v2.5
 
* do you have same script in the internal repo?
[Ram] : Jenkinsfile and vars/buildUtils.groovy are in the same repo

TIA,
/Ram

Torsten Reinhard

unread,
Dec 26, 2016, 12:18:55 PM12/26/16
to Jenkins Users
Hi

try to separate your Jenkinsfile from the code of your shared library. Usually the shared library provides some global functions that you may re-use in some Jenkinsfile(s)
=> the library is shared code, the Jenkinsfile belongs to your project(s) using that library.

Than, make sure you know what version of the library you are using:
- configure it in Jenkins/manage Jenkins -> global shared library. Here you´ll have to setup repo, branch, credentials to your shared library.
You can also configure it on a per folder base and you may reference it using the annotation@Library('somelib')

It´s pretty well documented at https://github.com/jenkinsci/workflow-cps-global-lib-plugin/blob/master/README.md

Good luck!

Best regards, Torsten

Ramanathan Muthaiah

unread,
Dec 30, 2016, 4:11:16 AM12/30/16
to Jenkins Users
Hi Torsten,

 
try to separate your Jenkinsfile from the code of your shared library. Usually the shared library provides some global functions that you may re-use in some Jenkinsfile(s)
=> the library is shared code, the Jenkinsfile belongs to your project(s) using that library.

[Ram] : I did start writing the library with this separation ; after re-reading the documentation, moved this library has been moved to it's own repo.

Than, make sure you know what version of the library you are using:
- configure it in Jenkins/manage Jenkins -> global shared library. Here you´ll have to setup repo, branch, credentials to your shared library.
You can also configure it on a per folder base and you may reference it using the annotation@Library('somelib')

[Ram] : Updated this configuration too.

With these changes, global shared libs are now usable from the Jenkinsfile.

/Ram
 
Reply all
Reply to author
Forward
0 new messages