我正在尝试使用Groovy构建一个管道,一切正常但是当我尝试在每个循环中调用一个方法时,它无法看到它。
(我对groovy有非常基本的了解)。 这是我得到的错误:
java.lang.NoSuchMethodError: No such DSL method 'sendToSlack' found among steps [ansiblePlaybook, ansibleVault, archive, bat, build, catchError, checkout, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, dockerNode, ec2, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, findFiles, getContext, git, httpRequest, input, isUnix, jiraComment, jiraIssueSelector, jiraSearch, junit, library, libraryResource, load, mail, milestone, node, nodesByLabel, parallel, powershell, properties, publishHTML, pwd, readFile, readJSON, readManifest, readMavenPom, readProperties, readTrusted, readYaml, resolveScm, retry, script, setGitHubPullRequestStatus, sh, sha1, slackSend, sleep, sshagent, stage, stash, step, svn, tee, timeout, tm, tool, touch, unarchive, unstash, unzip, validateDeclarativePipeline, waitForQualityGate, waitUntil, withContext, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, wrap, writeFile, writeJSON, writeMavenPom, writeYaml, ws, zip] or symbols [absolute, agent, all, allOf, allure, always, ant, antFromApache, antOutcome, antTarget, any, anyOf, apiToken, architecture, archiveArtifacts, artifactManager, attach, authorizationMatrix, batchFile, bitbucket, booleanParam, branch, brokenBuildSuspects, brokenTestsSuspects, buildButton, buildDiscarder, buildParameter, bzt, caseInsensitive, caseSensitive, certificate, changelog, changeset, checkoutToSubdirectory, checkstyle, choice, choiceParam, clock, cloud, command, configFile, configFileProvider, copyArtifacts, credentials, cron, c
以下是我要调用的循环:
def slack = load 'jenkins-pipeline/utils.groovy'
stage 'Automation local tests'
slack.sendToSlack('good', "Starting UI tests")
partners.each {
utils.sendToSlack("=============> Start UI test for ${it.name} <=============");
cmd = "node_modules/.bin/protractor node_modules/ct-ui-automation/conf.js --params.browsers='chrome_headless' --baseUrl='${part.url}?version=${verJson}' --directConnect --specs='node_modules/ct-ui-automation/ui_tests/gt/common/specs/e2e_spec/*/*'' --params.buildNumber='${verJson}' --params.environment='external-dev'";
def res = sh(returnStdout: true, script: cmd)
slack.sendToSlack("=============> END UI test for ${it.name}, ${it.url} <=============");
}
如何在slack.sendToSlack
内调用partners.each
方法?
utils的内容:
void sendToSlack(colorCode, teamMessage) {
try {
slackSend([
channel: '#somechannel',
color: colorCode,
message: teamMessage,
teamDomain: 'domain',
token: 'token'
])
}
catch(e) {
echo 'sendToSlack() error: ' + e.message;
}
}
return this;