开发者问题收集

Jenkins 更新后出现错误:java.lang.NoSuchMethodError:在步骤中未找到此类 DSL 方法“管道”

2020-05-04
7404

在我将 Jenkins 版本从 2.224 更新到 2.234 以及将所有插件更新到最新版本后,我的 Jenkins 管道出现故障。

下面是我的管道脚本,它与旧版 Jenkins 和旧版插件配合使用时运行良好。

随着 Jenkins 和插件的更新,管道出现故障。

pipeline { 
        agent none    
        stages {
             stage ("Check Parameters") { 
                   steps {
                       echo "In pipeline"
                          script {
                            echo "Start condition check"
                          }
                    }
                }
            }
    }

以上只是一个示例,因为实际的管道脚本非常庞大,我不希望让读者感到困惑。

运行管道时出现以下错误

[Pipeline] Start of Pipeline
    [Pipeline] End of Pipeline
    java.lang.NoSuchMethodError: No such DSL method 'pipeline' found among steps [ansiColor, ansiblePlaybook, ansibleTower, ansibleTowerProjectRevision, ansibleTowerProjectSync, ansibleVault, archive, bat, catchError, checkout, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, dockerNode, echo, emailext, emailextrecipients, error, fileExists, findBuildScans, getContext, git, input, isUnix, junit, library, libraryResource, load, lock, mail, node, parallel, powershell, properties, publishHTML, pwd, pwsh, readFile, readTrusted, resolveScm, retry, sh, sleep, stage, stash, step, svn, task, timeout, tm, tool, unarchive, unstable, unstash, waitUntil, warnError, withContext, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, withGradle, wrap, writeFile, ws] or symbols [all, always, ant, antFromApache, antOutcome, antTarget, apiToken, architecture, archiveArtifacts, artifactManager, attach, authorizationMatrix, batchFile, booleanParam, brokenBuildSuspects, brokenTestsSuspects, buildButton, buildDiscarder, buildDiscarders, buildFailureAnalyzer, caseInsensitive, caseSensitive, certificate, choice, choiceParam, cleanWs, clock, command, credentials, cron, crumb, cssText, cssUrl, culprits, defaultFolderConfiguration, defaultView, demand, developers, disableConcurrentBuilds, disableResume, docker, dockerCert, dockerfile, downstream, dumb, durabilityHint, envInject, envVars, faviconUrl, file, fileParam, filePath, fingerprint, frameOptions, freeStyle, freeStyleJob, fromScm, fromSource, ftpPublisher, git, gitBranchDiscovery, gitHubBranchDiscovery, gitHubBranchHeadAuthority, gitHubExcludeArchivedRepositories, gitHubForkDiscovery, gitHubPullRequestDiscovery, gitHubSshCheckout, gitHubTagDiscovery, gitHubTrustContributors, gitHubTrustEveryone, gitHubTrustNobody, gitHubTrustPermissions, gitParameter, gitTagDiscovery, github, githubPush, gradle, headRegexFilter, headWildcardFilter, hyperlink, hyperlinkToModels, inheriting, inheritingGlobal, installSource, jdk, jdkInstaller, jgit, jgitapache, jnlp, jobBuildDiscarder, jobName, jsUrl, lastDuration, lastFailure, lastGrantedAuthorities, lastStable, lastSuccess, legacy, legacySCM, list, local, location, logRotator, loggedInUsersCanDoAnything, mailer, masterBuild, maven, maven3Mojos, mavenErrors, mavenMojos, mavenWarnings, modernSCM, myView, newContainerPerStage, nodeProperties, nonInheriting, none, overrideIndexTriggers, paneStatus, parameterizedCron, parameters, password, pattern, permanent, pipeline-model, pipeline-model-docker, pipelineTriggers, plainText, plugin, pollSCM, projectNamingStrategy, proxy, queueItemAuthenticator, quietPeriod, rateLimitBuilds, recipients, requestor, resourceRoot, run, runParam, sSHLauncher, schedule, scmRetryCount, scriptApproval, scriptApprovalLink, search, security, shell, simple-theme-plugin, simpleBuildDiscarder, slave, sourceRegexFilter, sourceWildcardFilter, ssh, sshPublicKey, sshPublisher, sshPublisherDesc, sshTransfer, sshUserPrivateKey, standard, status, string, stringParam, swapSpace, teamSlugFilter, text, textParam, timezone, tmpSpace, toolLocation, unsecured, upstream, upstreamDevelopers, userSeed, usernameColonPassword, usernamePassword, validatingString, viewsTabBar, weather, withAnt, zfs, zip] or globals [currentBuild, docker, env, params, scm]
        at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:202)
        at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
        at sun.reflect.GeneratedMethodAccessor232.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:163)
        at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
        at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
        at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:142)
        at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
        at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
        at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
        at WorkflowScript.run(WorkflowScript:1)
        at ___cps.transform___(Native Method)
        at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
        at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
        at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
        at sun.reflect.GeneratedMethodAccessor231.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
        at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
        at com.cloudbees.groovy.cps.Next.step(Next.java:83)
        at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
        at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
        at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
        at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
        at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
        at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
        at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
        at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
        at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:400)
        at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
        at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
        at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
        at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
        at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
        at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
    Finished: FAILURE

插件管理器已安装 选项卡下显示的当前更新的最新版本的管道插件如下: 我发现之前在已安装的插件下可以看到但缺少的一件事是管道:版本 2.6

经过研究,我下载了 https://plugins.jenkins.io/workflow-aggregator/ hpi 文件,但是,当我在离线模式下安装此插件时,它会尝试拉取依赖项,如 Pipeline Milestone Step 等。

安装此 hpi 文件及其依赖项是否可以解决我的问题?请澄清。

Build Pipeline Plugin
    This plugin renders upstream and downstream connected jobs that typically form a build pipeline. In addition, it offers the ability to define manual triggers for jobs that require intervention prior to execution, e.g. an approval process outside of Jenkins.
    1.5.8       
        
    Delivery Pipeline Plugin
    This plugin visualize Delivery Pipelines (Jobs with upstream/downstream dependencies)
    1.4.2       
            
    Pipeline Graph Analysis Plugin
    Provides a REST API to access pipeline and pipeline run data.
    1.10        
        
    Pipeline: API
    Plugin that defines Pipeline API.
    2.40        
        
    Pipeline: Basic Steps
    Commonly used steps for Pipelines.
    2.20    
        
    Pipeline: Declarative Extension Points API
    APIs for extension points used in Declarative Pipelines.
    1.6.0       
        
    Pipeline: GitHub Groovy Libraries
    Allows Pipeline Grrovy libraries to be loaded on the fly from GitHub.
    1.0     
        
    Pipeline: Groovy
    Pipeline execution engine based on continuation passing style transformation of Groovy scripts.
    2.80        
        
    Pipeline: Input Step
    Adds the Pipeline step input to wait for human input or approval.
    2.11        
        
    Pipeline: Job
    Defines a new job type for pipelines and provides their generic user interface.
    2.39    
        
    Pipeline: Model API
    Model API for Declarative Pipeline.
    1.6.0       
        
    Pipeline: Multibranch
    Enhances Pipeline plugin to handle branches better by automatically grouping builds from different branches.
    2.21        
        
    Pipeline: Nodes and Processes
    Pipeline steps locking agents and workspaces, and running external processes that may survive a Jenkins restart or slave reconnection.
    2.35        
        
    Pipeline: REST API Plugin
    Provides a REST API to access pipeline and pipeline run data.
    2.13        
        
    Pipeline: SCM Step
    Adds a Pipeline step to check out or update working sources from various SCMs (version control).
    2.11    
        
    Pipeline: Shared Groovy Libraries
    Shared libraries for Pipeline scripts.
    2.16    
        
    Pipeline: Stage Step
    Adds the Pipeline step stage to delineate portions of a build.
    2.3     
        
    Pipeline: Stage View Plugin
    Pipeline Stage View Plugin.
    2.13        
        
    Pipeline: Step API
    API for asynchronous build step primitive.
    2.22        
        
    Pipeline: Supporting APIs
    Common utility implementations to build Pipeline Plugin
    3.4     

我没有互联网连接,必须手动复制插件。

我确实看到了几个插件旁边的降级按钮。但是,由于漏洞和错误修复,不希望降级。

您能建议一些解决方案吗?

2个回答

问题是没有安装管道插件。因此我下载了管道插件版本 2.6

https://plugins.jenkins.io/workflow-aggregator/

然后我下载了以下依赖项:

https://www.jenkins.io/doc/pipeline/steps/pipeline-build-step/
https://updates.jenkins.io/download/plugins/pipeline-milestone-step/
https://plugins.jenkins.io/pipeline-model-definition/
https://plugins.jenkins.io/pipeline-model-declarative-agent/
https://plugins.jenkins.io/pipeline-stage-tags-metadata/ 

在离线模式下逐一安装它们,问题得到解决。

Ashar
2020-05-04

就我而言,安装了 Ansible 插件,但存在一些导致该问题的安全问题。我更新了 Ansible 插件,重新启动了 Jenkins,执行了管道作业,它就正常工作了。

如果您安装了插件,请检查 管理 Jenkins 部分中是否有需要解决的安全警告。

您需要检查 Ansible 是否已启用。

  • 导航到 管理 Jenkins -> 管理插件 -> 已安装 并检查“ Ansible 插件 ”是否 已启用
  • 如果没有,请启用它并按下底部的重新启动按钮。

最后一步是配置 Ansible

  • 转到 管理 Jenkins ->全局工具配置
  • 向下滚动并转到 Ansible 部分,然后单击“ Ansible 安装...
  • 名称 字段中,设置您想要的任何名称
  • Ansible 可执行文件目录的路径 中设置“/usr/bin/”(适用于 Ubuntu)

要获取 Ansible 安装的路径,请在终端中使用 $ which ansible

Muhammad Tariq
2021-04-27