Jenkins Pipelines:为什么CPS Global Lib没有加载?

Keb*_*bbi 2 jenkins jenkins-pipeline

我正在关注管道库插件的教程.我创建了一个包含以下文件的存储库:

D:.
?   Test.groovy
?   
????src
????vars
        helloWorld.groovy
Run Code Online (Sandbox Code Playgroud)

helloWorld.groovy包含:

def call(name){
    echo "Hello world, ${name}"
}
Run Code Online (Sandbox Code Playgroud)

Test.groovy包含:

helloWorld("Joe")
Run Code Online (Sandbox Code Playgroud)

我安装了所有管道插件,特别是workflow-cps-global-lib-plugin.然后我创建了一个新的管道作业,在其中加载此存储库并将脚本路径设置为Test.groovy.当我运行这个工作时,我收到以下错误:

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]
Run Code Online (Sandbox Code Playgroud)

为什么没有定义helloWorld步骤?这是我安装的插件列表:http://pastebin.com/xiMMub8J

小智 5

Pipeline Global Library期望Git推送事件更新Jenkins嵌入式工作流-libs git repo.

推送触发该UserDefinedGlobalVariableList.rebuild()方法请参阅:https://github.com/jenkinsci/workflow-cps-global-lib-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/cps/global/UserDefinedGlobalVariableList的.java

这是一个groovy脚本,它将GitHub存储库拉入Jenkins存储workflow-libs库,然后通过以下方式重新加载它而不重新启动:

//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