Search code examples
jenkinsjenkins-pipeline

New to Jenkins; simple build fails with No such DSL method 'pipeline' found among steps


I have a simple hello world project which is failing on a new Jenkins install. I'm following the instructions in this URL: https://code-maven.com/jenkins-pipeline-hello-world

For reference, the following simple build pipeline plugins are installed:

Build Pipeline Plugin 1.5.8
Pipeline Keep Running Step 1.0
Pipeline Utility Steps 2.6.1
Pipeline: API 2.40
Pipeline: Basic Steps 2.22
Pipeline: Build Step 2.13
Pipeline: Groovy 2.85
Pipeline: Input Step 2.12
Pipeline: Job 2.40
Pipeline: Keep Environment Step Plugin 1.0
Pipeline: Nodes and Processes 2.36
Pipeline: REST API Plugin 2.18
Pipeline: SCM Step 2.11
Pipeline: Stage Step 2.5
Pipeline: Stage View Plugin 2.18
Pipeline: Step API 2.23
Pipeline: Supporting APIs 3.6
Lockable Resources

(so that also makes the following links I read before posting not applicable: Jenkins pipeline - No such DSL method 'build', Jenkins Pipeline - java.lang.NoSuchMethodError: No such DSL method 'lock' found among steps, No such DSL method 'pipeline' found among steps)

So per the tutorial I'm following, I created a pipeline, and in the configuration put the following code in the "Pipeline" section:

pipeline {
    agent { label 'master' }
    stages {
        stage('build') {
            steps {
                echo "Hello World!"
            }
        }
    }
}

When I click the "Build Now" button, I get the following from the console output:

Started by user dogzilla
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] End of Pipeline
java.lang.NoSuchMethodError: No such DSL method 'pipeline' found among steps [archive, bat, build, catchError, checkout, compareVersions, deleteDir, dir, echo, error, fileExists, findFiles, getContext, input, isUnix, junit, keepEnv, keepRunning, load, lock, mail, node, nodesByLabel, parallel, powershell, publishChecks, pwd, pwsh, readCSV, readFile, readJSON, readManifest, readMavenPom, readProperties, readYaml, retry, sh, sha1, sleep, stage, stash, step, tee, timeout, tm, tool, touch, unarchive, unstable, unstash, unzip, waitUntil, warnError, withContext, withEnv, wrap, writeCSV, writeFile, writeJSON, writeMavenPom, writeYaml, ws, zip] or symbols [all, always, apiToken, architecture, archiveArtifacts, artifactManager, batchFile, booleanParam, buildButton, buildDiscarder, buildDiscarders, caseInsensitive, caseSensitive, choice, choiceParam, clock, command, credentials, cron, crumb, defaultView, demand, disableConcurrentBuilds, disableResume, downstream, dumb, durabilityHint, envVars, envVarsFilter, file, fileParam, filePath, fingerprint, fingerprints, frameOptions, freeStyle, freeStyleJob, fromScm, fromSource, headRegexFilter, headWildcardFilter, hyperlink, hyperlinkToModels, installSource, javadoc, jdk, jdkInstaller, jnlp, jobBuildDiscarder, jobName, junitTestResultStorage, lastDuration, lastFailure, lastGrantedAuthorities, lastStable, lastSuccess, legacy, list, local, location, logRotator, loggedInUsersCanDoAnything, mailer, masterBuild, maven, maven3Mojos, mavenErrors, mavenMojos, mavenWarnings, myView, nodeProperties, none, paneStatus, parameters, password, pattern, permanent, pipelineTriggers, plainText, plugin, pollSCM, projectNamingStrategy, proxy, queueItemAuthenticator, quietPeriod, resourceRoot, retainOnlyVariables, run, runParam, schedule, scmRetryCount, scriptApproval, scriptApprovalLink, search, security, shell, simpleBuildDiscarder, slave, sourceRegexFilter, sourceWildcardFilter, sshPublicKey, standard, status, string, stringParam, swapSpace, text, textParam, timezone, tmpSpace, toolLocation, unsecured, upstream, userSeed, viewsTabBar, weather, zfs, zip] or globals [currentBuild, env, params]
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:216)
    at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    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:163)
    at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:142)
    at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
    at WorkflowScript.run(WorkflowScript:1)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    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$001(SandboxContinuable.java:18)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:400)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:136)
    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

Curious as to why this is failing. If there's a java problem, Jenkins won't even start. I have all the plugins installed that are in the instructions and some of the troubleshooting links I've read.

How can I get this working?


Solution

  • I came across the answer while someone was helping me on a different forum. Posting here in case it's useful to anyone else down the road.

    In https://www.jenkins.io/doc/book/pipeline/syntax/, it says:

    All valid Declarative Pipelines must be enclosed within a pipeline block, for example:

    pipeline {
    
    /* insert Declarative Pipeline here */
    
    }
    

    So when I wrapped the example script in pipeline {}, it works.