Jenkins Pipelines: Why is CPS Global Lib not loading?

穿精又带淫゛_ 提交于 2019-12-02 06:17:41

问题


I'm following the tutorial on the pipeline library plugin. I made a repository containing the following files:

D:.
│   Test.groovy
│   
├───src
└───vars
        helloWorld.groovy

helloWorld.groovy contains:

def call(name){
    echo "Hello world, ${name}"
}

Test.groovy contains:

helloWorld("Joe")

I installed all the pipeline plugins, in particular workflow-cps-global-lib-plugin. Then I created a new pipeline job in which I load this repository and set the Script Path to Test.groovy. When I run this job I get the following error:

java.lang.NoSuchMethodError: No such DSL method 'helloWorld' found among [archive, bat, build, catchError, checkout, deleteDir, dir, echo, emailext, error, fileExists, git, input, isUnix, jiraComment, jiraIssueSelector, jiraSearch, load, mail, node, parallel, properties, pwd, readFile, readTrusted, retry, sh, sleep, stage, stash, step, svn, timeout, tool, unarchive, unstash, waitUntil, withEnv, wrap, writeFile, ws]

Why is the helloWorld step not defined? Here is my list of installed plugins: http://pastebin.com/xiMMub8J


回答1:


The Pipeline Global Library expects a Git push event to update the Jenkins embedded workflow-libs git repo.

A push triggers the UserDefinedGlobalVariableList.rebuild() method see: https://github.com/jenkinsci/workflow-cps-global-lib-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/cps/global/UserDefinedGlobalVariableList.java

Here is a groovy script that pulls a GitHub repo into the Jenkins workflow-libs repos and then reloads it without a restart via:

//Get Pipeline Global Library Jenkins Extension that rebuilds global library on Git Push List extensions = ExtensionList.lookup(UserDefinedGlobalVariableList.class); extensions.get(0).rebuild() //may want to add a check here to make sure extensions isn't null




回答2:


Using the 2.8 version of Pipeline:Groovy plugin I found that if I update the groovy scripts under /vars/myscript.groovy doesn't work, but if I restart jenkins everything works fine. If I simply reload configuration from file, nothing happens.

So I think the scripts are instantiated as global functions only when jenkins start. (but maybe I'm wrong :) )



来源:https://stackoverflow.com/questions/38073300/jenkins-pipelines-why-is-cps-global-lib-not-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!