<p>I try to use the post steps with the Jenkins kubernetes plugin. Does anyone has an idea?</p>

<pre><code>java.lang.NoSuchMethodError: No such DSL method 'post' found among steps
</code></pre>

<p>My pipeline:</p>

<pre><code>podTemplate(
        label: 'jenkins-pipeline',
        cloud: 'minikube',
        volumes: [
                hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
        ]) {

    node('jenkins-pipeline') {
        stage('test') {
            container('maven') {
                println 'do some testing stuff'
            }
        }

        post {
            always {
                println "test"
            }
        }
    }
}
</code></pre>

<p>This example shows how to use the post step using the Kubernetes plugin:</p>
<pre><code>pipeline {
  agent {
    kubernetes {
      label &quot;my-test-pipeline-${BUILD_NUMBER}&quot;
      containerTemplate {
        name &quot;my-container&quot;
        image &quot;alpine:3.15.0&quot;
        command &quot;sleep&quot;
        args &quot;99d&quot;
      }
    }
  }
  stages {
    stage('Stage 1') {
      steps {
        container('my-container') {
          sh '''
            set -e
            echo &quot;Hello world!&quot;
            sleep 10
            echo &quot;I waited&quot;

            echo &quot;forcing a fail&quot;
            exit 1
          '''
        }
      }
    }
  }
  post {
    unsuccessful {
      container('my-container') {
        sh '''
          set +e
          echo &quot;Cleaning up stuff here&quot;
        '''
      }
    }
  }
}
</code></pre>
