一尘不染

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

jenkins

我正在关注有关管道库插件的教程。我制作了一个包含以下文件的存储库:

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

helloWorld.groovy包含:

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

Test.groovy包含:

helloWorld("Joe")

我安装了所有管道插件,尤其是工作流-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]

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


阅读 279

收藏
2020-07-25

共1个答案

一尘不染

Pipeline全球图书馆希望Git推送事件能够更新Jenkins嵌入式工作流库git repo。

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

这是一个普通的脚本,它将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

2020-07-25