java.lang.nosuche,Jenkins java.lang.NoSuchMethodError:在步骤中找不到这样的DSL方法'post'...

I'm trying to implement a stage on jenkins to send email when a failure is produced on jenkins. I made something similiar to the jenkins documention:

#!/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}"

}

}

}

}

But i always get this error:

java.lang.NoSuchMethodError: No such DSL method 'post' found among

steps [archive, bat, build, catchError, checkout, deleteDir, dir,

dockerFingerprintFrom, dockerFingerprintRun, echo, emailext,

emailextrecipients, envVarsForTool, error, fileExists, getContext,

git, input, isUnix, library, libraryResource, load, mail, milestone,

node, parallel, powershell, properties, publishHTML, pwd, readFile,

readTrusted, resolveScm, retry, script, sh, sleep, stage, stash, step,

svn, timeout, timestamps, tm, tool, unarchive, unstash,

validateDeclarativePipeline, waitUntil, withContext, withCredentials,

withDockerContainer, withDockerRegistry, withDockerServer, withEnv,

wrap, writeFile, ws] or symbols [all, allOf, always, ant,

antFromApache, antOutcome, antTarget, any, anyOf, apiToken,

architecture, archiveArtifacts, artifactManager, authorizationMatrix,

batchFile, booleanParam, branch, buildButton, buildDiscarder,

caseInsensitive, caseSensitive, certificate, changelog, changeset,

choice, choiceParam, cleanWs, clock, cloud, command, credentials,

cron, crumb, defaultView, demand, disableConcurrentBuilds, docker,

dockerCert, dockerfile, downloadSettings, downstream, dumb, envVars,

environment, expression, file, fileParam, filePath, fingerprint,

frameOptions, freeStyle, freeStyleJob, fromScm, fromSource, git,

github, githubPush, gradle, headRegexFilter, headWildcardFilter,

hyperlink, hyperlinkToModels, inheriting, inheritingGlobal,

installSource, jacoco, jdk, jdkInstaller, jgit, jgitapache, jnlp,

jobName, junit, label, lastDuration, lastFailure,

lastGrantedAuthorities, lastStable, lastSuccess, legacy, legacySCM,

list, local, location, logRotator, loggedInUsersCanDoAnything,

masterBuild, maven, maven3Mojos, mavenErrors, mavenMojos,

mavenWarnings, modernSCM, myView, node, nodeProperties, nonInheriting,

nonStoredPasswordParam, none, not, overrideIndexTriggers, paneStatus,

parameters, password, pattern, pipeline-model, pipelineTriggers,

plainText, plugin, pollSCM, projectNamingStrategy, proxy,

queueItemAuthenticator, quietPeriod, remotingCLI, run, runParam,

schedule, scmRetryCount, search, security, shell, skipDefaultCheckout,

skipStagesAfterUnstable, slave, sourceRegexFilter,

sourceWildcardFilter, sshUserPrivateKey, stackTrace, standard, status,

string, stringParam, swapSpace, text, textParam, tmpSpace,

toolLocation, unsecured, upstream, usernameColonPassword,

usernamePassword, viewsTabBar, weather, withAnt, zfs, zip] or globals

[currentBuild, docker, env, params, pipeline, scm]

I saw some others post, but the suggestion made did not work for me

解决方案

I was having the same problem here. Lots of examples for declarative... none for scripted. It almost leads you to believe that there is no solution, but that wouldn't make sense.

This worked for me (it works without the try/finally -- or catch if you want).

node {

//some var declarations... or whatever

try {

//do some stuff, run your tests, etc.

} finally {

junit 'build/test-results/test/*.xml'

}

}

*EDIT: take a look at their documentation... accidentally I've done exactly what they recommend. Just click on the "Toggle Scripted Pipeline (Advanced)" link and you'll see it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值