我正在学习 pipeline library plugin 上的教程.我创建了一个包含以下文件的存储库:
D:.
│ Test.groovy
│
├───src
└───vars
helloWorld.groovy
helloWorld.groovy 包含:
def call(name){
echo "Hello world, ${name}"
}
Test.groovy 包含:
helloWorld("Joe")
我安装了所有管道插件,特别是 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]
为什么没有定义 helloWorld 步骤?这是我安装的插件列表:http://pastebin.com/xiMMub8J
最佳答案
管道全局库需要 Git 推送事件来更新 Jenkins 嵌入式工作流库 git 存储库。
推送触发 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 script将 GitHub 存储库拉入 Jenkins workflow-libs
存储库,然后通过以下方式重新加载它而无需重新启动:
//在Git Push上获取重建全局库的Pipeline Global Library Jenkins Extension
列表扩展 = ExtensionList.lookup(UserDefinedGlobalVariableList.class);
extensions.get(0).rebuild()//可能需要在此处添加检查以确保扩展不为空
关于 Jenkins 管道 : Why is CPS Global Lib not loading?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38073300/