<p>I'm going to deploy my docker image to the k8s cluster using jenkins CICD.</p>
<p>I installed Kubernetes CLI and SSH Agent in Jenkins.</p>
<p>I used the below code.</p>
<pre><code>stage('List pods') {
    withKubeConfig([credentialsId: 'kubectl-user']) {
        sh 'curl -LO &quot;https://storage.googleapis.com/kubernetes-release/release/v1.20.5/bin/linux/amd64/kubectl&quot;'  
        sh 'chmod u+x ./kubectl'  
        sh './kubectl get pods -n dev'
    }
  }
</code></pre>
<p>And, I'm getting the below error.</p>
<pre><code>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 39: Unknown stage section &quot;withKubeConfig&quot;. Starting with version 0.5, steps in a stage must be in a ‘steps’ block. @ line 39, column 2.
    stage('List pods') {
    ^

WorkflowScript: 39: Expected one of &quot;steps&quot;, &quot;stages&quot;, or &quot;parallel&quot; for stage &quot;List pods&quot; @ line 39, column 2.
    stage('List pods') {
    ^

2 errors

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
    at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:571)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:523)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
</code></pre>
<p>Have I missed anything?</p>

prime
<p>It seems like you are using <a href="https://www.jenkins.io/doc/book/pipeline/#scripted-pipeline-fundamentals" rel="nofollow noreferrer">scripted pipeline syntax</a> inside a declarative pipeline and therefore you are seeing the error.</p>
<p>If you  want to use declarative pipeline syntax you must follow the strict <a href="https://www.jenkins.io/doc/book/pipeline/syntax/" rel="nofollow noreferrer">formatting guidelines</a>, in your case you are missing the steps directive under the stage directive.<br />
Your code should look something like:</p>
<pre><code>pipeline {
    agent any
    stages {
       stage('List Pods') {
           steps {
               withKubeConfig([credentialsId: 'kubectl-user']) {
                   sh 'curl -LO &quot;https://storage.googleapis.com/kubernetes-release/release/v1.20.5/bin/linux/amd64/kubectl&quot;'
                   sh 'chmod u+x ./kubectl'
                   sh './kubectl get pods -n dev'
               }
           }
       }
    }
}
</code></pre>
<p>If you want to use the scripted pipeline syntax it will look something like:</p>
<pre><code>node {
    stage('List Pods') {
        withKubeConfig([credentialsId: 'kubectl-user']) {
            sh 'curl -LO &quot;https://storage.googleapis.com/kubernetes-release/release/v1.20.5/bin/linux/amd64/kubectl&quot;'
            sh 'chmod u+x ./kubectl'
            sh './kubectl get pods -n dev'
        }
    }
}
</code></pre>
<p>You can <a href="https://www.jenkins.io/doc/book/pipeline/syntax/#compare" rel="nofollow noreferrer">read more here</a> about the differences between the two pipelines syntaxes.</p>
