Jenkins 管道 : Why is CPS Global Lib not loading?

标签 jenkins jenkins-pipeline

我正在学习 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/

相关文章:

c# - Jenkins 无法通过缺少对程序集 netstandard 的引用来构建 Xamarin iOS 项目

jenkins - 运行Jenkins管道时如何修复 'script returned exit code 1'

jenkins - 如何以编程方式批准 Jenkins 系统 Groovy 脚本

jenkins - 如何编写 Pipeline 来丢弃旧版本?

jenkins - 防止 Jenkins 在首次运行/种子作业时构建多分支管道的所有分支?

jenkins - 无法将 Jenkins 中的存储库连接到 GitLab

java 内存设置 amazon m3.xlarge

jenkins-pipeline - 如何使用 jobname/{env.BRANCH_NAME} 触发多分支下游作业

jenkins - 如何屏蔽 Jenkins Pipeline 项目中的密码字段?