我正试图读取詹金斯管道中的一个文件。
#!groovy
// pipeline config
def javaAgent = 'build && java'
def environment = "test"
def machineName = "dev1"
@Library(['my-lib@feature/jenkins-pipeline-for-index-creation']) _
// pipeline
node(javaAgent) {
properties([
[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator',daysToKeepStr: '1', numToKeepStr: '4']],
parameters([
choice(
choices: ["test","production"].join("\n"),
defaultValue: 'test',
description: 'Env for Index deployment',
name: 'environment'
)
])
])
try{
stage('Collect info') {
checkout scm
}
stage('Creating Indexes'){
environment=params.environment
if(environment=="production"){
machineName = "prod1"
}
myVar.createIndexes environment: environment,
deployToMachine: machineName
}
} catch (e){
pcSlack.notify channel:"ksr", message: ${environment}+" Couchbase index creation failed : "+e
currentBuild.result = 'FAILURE'
}
}
为此,我在我的jenkins文件中导入的库中定义了下面的函数。
void createIndexes(Map args) {
String files = sh script: "ls -lart", returnStdout: true
echo "workspace files: ${files}"
def filePath = readFile('./indexes/test.txt')
def queries = filePath.readLines()
//To-do Add code for reading queries
}
但是,我一直得到以下例外。
[Pipeline] Start of Pipeline
[Pipeline] node
Running on build-java-1 in /home/jenkins/agent/workspace/..
[Pipeline] {
[Pipeline] properties
[Pipeline] stage
[Pipeline] { (Collect info)
[Pipeline] checkout
Fetching changes from the remote Git repository
..
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Creating Indexes)
[Pipeline] sh
+ ls -lart
[Pipeline] echo
workspace files: total 96
drwxr-xr-x 4 jenkins jenkins 4096 Jan 24 11:06 ..
..
drwxr-xr-x 2 jenkins jenkins 4096 Jan 24 11:07 indexes
..
drwxr-xr-x 8 jenkins jenkins 4096 Jan 24 11:16 .git
[Pipeline] readFile
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
Terminated
[Pipeline] // node
[Pipeline] End of Pipeline
[Office365connector] No webhooks to notify
java.lang.NoSuchMethodError: No such DSL method '$' found among steps [ArtifactoryGradleBuild, MavenDescriptorStep, addBadge, addErrorBadge, addHtmlBadge, addInfoBadge, addInteractivePromotion, addShortText, addWarningBadge, ansiColor, ansiblePlaybook, ansibleVault, archive, artifactoryDistributeBuild, artifactoryDownload, artifactoryMavenBuild, artifactoryPromoteBuild, artifactoryUpload, bat, bitbucketStatusNotify, build, catchError, checkout, collectEnv, conanAddRemote, conanAddUser, createSummary, deleteDir, deployArtifacts, dir, dockerFingerprintFrom, dockerFingerprintRun, dockerPullStep, dockerPushStep, dockerPushWithProxyStep, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, findFiles, getArtifactoryServer, getContext, git, httpRequest, initConanClient, input, isUnix, jiraComment, jiraIssueSelector, jiraSearch, junit, library, libraryResource, load, loadRunnerTest, lock, mail, milestone, neoloadRefreshTrends, neoloadRun, newArtifactoryServer, newBuildInfo, newGradleBuild, newMavenBuild, node, nodesByLabel, office365ConnectorSend, parallel, powershell, properties, publishBuildInfo, publishHTML, pwd, pybat, pysh, readFile, readJSON, readManifest, readMavenPom, readProperties, readTrusted, readYaml, removeBadges, removeHtmlBadges, removeSummaries, resolveScm, retry, runConanCommand, runLoadRunnerScript, script, sh, sha1, slackSend, sleep, sseBuildAndPublish, sshagent, stage, stash, step, svChangeModeStep, svDeployStep, svExportStep, svUndeployStep, svn, task, tee, timeout, timestamps, tm, tool, touch, uftScenarioLoad, unarchive, unstash, unzip, validateDeclarativePipeline, waitForQualityGate, waitUntil, withContext, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, withMaven, withPythonEnv, wrap, writeFile, writeJSON, writeMavenPom, writeYaml, ws, xrayScanBuild, xunit, zip] or symbols [AUnit, BoostTest, CTest, CUnit, Check, CppTest, CppUnit, Custom, FPCUnit, GoogleTest, JUnit, MSTest, MbUnit, NUnit2, NUnit3, PHPUnit, QtTest, UftScenarioLoad, UnitTest, Valgrind, absolute, addALMOctaneSonarQubeListener, all, allOf, always, androidLint, ant, antFromApache, antOutcome, antTarget, any, anyOf, apiToken, aqua, architecture, archiveArtifacts, artifactManager, artifactsPublisher, authorizationMatrix, batchFile, bitbucket, bitbucketPush, bitbucketpr, booleanParam, branch, brokenBuildSuspects, brokenTestsSuspects, buildButton, buildDiscarder, buildParameter, buildingTag, bzt, caseInsensitive, caseSensitive, certificate, changeRequest, changelog, changeset, checkoutToSubdirectory, checkstyle, choice, choiceParam, cleanWs, clock, cloud, cobertura, command, concordionPublisher, configFile, configFileProvider, convertTestsToRun, copyArtifactPermission, copyArtifacts, credentials, cron, crumb, cucumber, culprits, defaultView, demand, dependenciesFingerprintPublisher, deployLambda, developers, disableConcurrentBuilds, disableResume, docker, dockerCert, dockerfile, downloadSettings, downstream, dry, dumb, durabilityHint, embUnit, envVars, environment, equals, eventSourceLambda, expression, extendedChoice, failed, file, fileCopyOperation, fileCreateOperation, fileDeleteOperation, fileDownloadOperation, fileJoinOperation, fileOperations, fileParam, filePath, filePropertiesToJsonOperation, fileRenameOperation, fileTransformOperation, fileUnTarOperation, fileUnZipOperation, fileZipOperation, findbugs, findbugsPublisher, fingerprint, folderCopyOperation, folderCreateOperation, folderDeleteOperation, folderRenameOperation, frameOptions, freeStyle, freeStyleJob, fromScm, fromSource, git, gitParameter, github, githubPush, globalConfigFiles, go, gradle, gtester, headRegexFilter, headWildcardFilter, healthAnalyzer, hyperlink, hyperlinkToModels, inheriting, inheritingGlobal, installSource, invokeLambda, invokerPublisher, isRestartedRun, jacoco, jacocoPublisher, jdk, jdkInstaller, jgit, jgitapache, jgivenPublisher, jnlp, jobDsl, jobName, junitPublisher, label, lastCompleted, lastDuration, lastFailure, lastGrantedAuthorities, lastStable, lastSuccess, lastSuccessful, latestSavedBuild, legacy, legacySCM, list, loadRunnerTest, local, location, logRotator, loggedInUsersCanDoAnything, masterBuild, maven, maven3Mojos, mavenErrors, mavenLinkerPublisher, mavenMojos, mavenWarnings, modernSCM, msbuild, msbuildError, msbuildWarning, myView, newContainerPerStage, node, nodeProperties, nonInheriting, none, not, notifyBitbucket, notifyStash, nunit, office365ConnectorSend, office365ConnectorWebhooks, openTasksPublisher, overrideIndexTriggers, paneStatus, parallelsAlwaysFailFast, parameters, passed, password, pattern, pcBuild, perfReport, performanceReport, performanceTest, permalink, permanent, pipeline-model, pipelineGraphPublisher, pipelineMaven, pipelineTriggers, plainText, plugin, pmd, pollSCM, preserveStashes, previous, projectNamingStrategy, proxy, publishGherkinResults, publishLambda, queueItemAuthenticator, quietPeriod, recipients, relative, requestor, run, runFromAlmBuilder, runLoadRunnerScript, runParam, schedule, scmRetryCount, scriptApprovalLink, search, security, shell, skipDefaultCheckout, skipStagesAfterUnstable, skipped, slave, snapshotDependencies, sourceRegexFilter, sourceWildcardFilter, specific, spotbugsPublisher, sseBuild, sshUserPrivateKey, stackTrace, standard, status, string, stringParam, swapSpace, tag, testCase, text, textParam, tmpSpace, toolLocation, triggeredBy, unsecured, uploadResultToALM, upstream, upstreamDevelopers, userSeed, usernameColonPassword, usernamePassword, veracode, veracodeDynamicRescan, viewsTabBar, weather, withAnt, withSonarQubeEnv, workspace, xUnitDotNet, zfs, zip] or globals [Artifactory, Constants, acceptanceTest, artifactoryUtils, assertions, bdd, bitbucketUtils, clair, currentBuild, docker, dockerUtils, env, fileLoader, giantswarm, gitUtils, gmpUtils, gradle, jenkinsUtils, kubectlUtils, manager, metadata, mvnUtils, npmUtils, params, pcArtifactory, pcBase, pcCouchbase, pcCouchbaseServer, pcK8s, pcPromote, pcSlack, pcapiBase, pcapiK8s, pcapiPromote, pipeline, pipelineUtils, scm, scp, serviceUtils, slackUtils, slaves, sonar, ssh, terminal, unixTimestamp, utils, veracodeUtils, xray]
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:199)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
at sun.reflect.GeneratedMethodAccessor392.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:158)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:155)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:156)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:160)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:130)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
at WorkflowScript.run(WorkflowScript:62)
at ___cps.transform___(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
at sun.reflect.GeneratedMethodAccessor391.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$101(SandboxContinuable.java:34)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:136)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:182)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
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
此外,如果我删除< code>readFile函数调用,我的jenkins管道将成功执行。
你知道这里有什么问题吗?
catch 块中的 slack 语句具有错误的字符串串联语法,应将 ${environment}
括在双引号 (“
) 中,或者删除 ${}
以解决此问题:
pcSlack.notify channel:"ksr", message: "${environment}"+" Couchbase index creation failed : "+e
pcSlack.notify channel:"ksr", message: environment+" Couchbase index creation failed : "+e
或者全部在单个字符串中:
pcSlack.notify channel:"ksr", message: "${environment} Couchbase index creation failed : ${e}"
我有以下dsl: 这会失败并出现以下错误 我做错了什么?我正在使用 Jenkins2.89.4 作业DSL 1.68 管道作业2.20 管道:API 2.27 管道:基本步骤2.7 管道:构建步骤2.7 管道:声明1.2.9
我正在尝试删除警告,。所以,我正在为阶段添加块 现在,詹金斯给出了错误 添加块是正确的做法吗?
我想运行bash命令抛出Jenkins管道,我正在调用一个具有一些bash命令的函数,但我得到这个错误: 这是函数: defcopy_tools(){ } 你能帮忙吗?
问题内容: 我正在尝试在jenkins上实现一个阶段,以在jenkins发生故障时发送电子邮件。我做了一些类似于詹金斯记录的东西: 但是我总是得到这个错误: java.lang.NoSuchMethodError:在步骤[archive,bat,build,catchError,checkout,deleteDir,dir,dockerFingerprintFrom,dockerFingerpri
我正在尝试在 Jenkins 上实现一个阶段,以便在 Jenkins 上产生故障时发送电子邮件。我做了一些类似于詹金斯文档的东西: 但是我总是得到这个错误: java.lang.NoSuchMethodError:在步骤中找不到这样的DSL方法“post”[archive,bat,build,catchError,checkout,deleteDir,dir,dockerFingerprintFr
我目前正在尝试使用jenkinsfile在jenkins中实现管道,我正在windows机器上执行一个maven项目。我正在jenkins中创建一个管道作业,我已经在我的github存储库中签入了这个文件,当我在jenkins中运行作业时,我收到了以下错误。 我的jenkinsfile: 我得到下面的错误,当我运行它通过詹金斯工作-Jenkins错误: java.lang.NoSuchMethod