title: Jenkins : java.lang.NoSuchMethodError: No such DSL method '$' found among steps
body: <p>I am trying to read a file inside jenkins pipeline.</p>
  <pre class="lang-groovy prettyprint-override"><code>#!groovy
  // pipeline config
  def javaAgent = 'build &amp;&amp; java'
  
  def environment = &quot;test&quot;
  def machineName = &quot;dev1&quot;
  
  @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: [&quot;test&quot;,&quot;production&quot;].join(&quot;\n&quot;),
                  defaultValue: 'test',
                  description: 'Env for Index deployment',
                  name: 'environment'
              )
          ])
      ])
      
      try{
          stage('Collect info') {
                  checkout scm
          }
          stage('Creating Indexes'){
          
              environment=params.environment
              if(environment==&quot;production&quot;){
                  machineName = &quot;prod1&quot;
              }   
              
              myVar.createIndexes environment: environment, 
                      deployToMachine: machineName        
  
          }
  
      } catch (e){
              pcSlack.notify channel:&quot;ksr&quot;, message: ${environment}+&quot; Couchbase index creation failed : &quot;+e
              currentBuild.result = 'FAILURE' 
      }   
  }
  </code></pre>
  <p>For that, i have defined below function in a library which I have imported in my jenkins file.</p>
  <pre class="lang-groovy prettyprint-override"><code>    void createIndexes(Map args) {
        String files = sh script: &quot;ls -lart&quot;, returnStdout: true
        echo &quot;workspace files: ${files}&quot;
        def filePath = readFile('./indexes/test.txt')                 
        def queries = filePath.readLines()   
        //To-do Add code for reading queries
      }
  </code></pre>
  <p>However, i keep getting below exception.</p>
  <pre class="lang-groovy prettyprint-override"><code>[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></pre>
  <p>Further, if i remove the <code>readFile</code> function call, my jenkins pipeline executes successfully.</p>
  <p>Any idea what is the issue here?</p>