当前位置: 首页 > 面试题库 >

Jenkins java.lang.NoSuchMethodError:在步骤之间找不到这样的DSL方法“ post”

彭俊智
2023-03-14
问题内容

我正在尝试在jenkins上实现一个阶段,以在jenkins发生故障时发送电子邮件。我做了一些类似于詹金斯记录的东西:

#!/usr/bin/env groovy

node {

stage ('Send Email') {

        echo 'Send Email'

            post {
                failure {
                    mail to: 'aa@bb.cc',
                         subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
                         body: "Something is wrong with ${env.BUILD_URL}"
                }
            }

        }

}

但是我总是得到这个错误:

java.lang.NoSuchMethodError:在步骤[archive,bat,build,catchError,checkout,deleteDir,dir,dockerFingerprintFrom,dockerFingerprintRun,echo,emailext,emailextrecipients,envVarsForTool,错误,fileExists,getContext,git中没有找到这样的DSL方法“
post”
,输入,isUnix,库,libraryResource,负载,邮件,里程碑,节点,并行,powershell,属性,publishHTML,pwd,readFile,readTrusted,resolveScm,重试,脚本,sh,sleep,stage,stash,step,svn,超时,时间戳记,tm,工具,未存档,取消隐藏,validateDeclarativePipeline,waitUntil,withContext,withCredentials,withDockerContainer,withDockerRegistry,withDockerServer,withEnv,wrap,writeFile,ws]或符号[all,allOf,always,ant,ant,antFromApache,antOutcome,antTarget,
any,anyOf,apiToken,架构,archiveArtifacts,artifactManager,authorizationMatrix,batchFile,booleanParam,分支,buildButton,buildDiscarder,caseInsensitive,caseSensitive,证书,changelog,changeset,select,choiceParam,cleanWs,时钟,云,命令,凭据,cron,面包屑,defaultView,需求,disableConcurrentBuilds,docker,
dockerCert,dockerfile,downloadSettings,下游,哑,envVars,环境,表达式,文件,fileParam,filePath,指纹,frameOptions,freeStyle,freeStyleJob,fromScm,fromSource,git,github,githubPush,gradle,headRegexFilter,headWildcardFilter,超链接,超链接ToModels,继承,InheritingGlobal,installSource,jacoco,jdk,jdkInstaller,jgit,jgitapache,jnlp,jobName,junit,label,lastDuration,lastFailure,lastGrantedAuthorities,lastStable,lastSuccess,legacy,legacySCM,列表,本地,位置,logRotator,loggedInUsersCanDoAnything,masterBuild,maven,maven3Mojos,mavenErrors,mavenMojos,mavenWarnings,modernSCM,myView,node,nodeProperties,非继承,nonStoredPasswordParam,none,not,overrideIndexTriggers,panelStatus,参数,密码,模式,管道模型插件,pollSCM,projectNamingStrategy,代理,queueItemAuthenticator,quietPeriod,remotingCLI,运行,runParam,计划,scmRetryCount,搜索,安全性,shell,skipDefaultCheckout,skipStagesAfterUnstable,从属,sourceRegexFilter,sourceWildcardFilter,sshUserPrivateKey,stackTrace,标准,状态,状态swapSpace,text,textParam,tmpSpace,toolLocation,不安全,上游,usernameColonPassword,usernamePassword,viewsTabBar,weather,withAnt,zfs,zip]或全局变量[currentBuild,docker,env,params,管道,scm]

我看到了其他人的帖子,但提出的建议对我没有用


问题答案:

我在这里遇到同样的问题。许多用于声明性的示例,没有用于脚本的示例。它几乎使您相信没有解决方案,但这没有任何意义。

这对我有用(无需尝试/最后也可以使用-如果需要,可以接住)。

node {
    //some var declarations... or whatever

    try {
        //do some stuff, run your tests, etc.            
    } finally {
        junit 'build/test-results/test/*.xml'
    }
}

*编辑:看看他们的文档 …偶然地,我完全按照他们的建议做了。只需单击“切换脚本管道(高级)”链接,您就会看到它。



 类似资料: