<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>As of this writing, <a href="https://issues.jenkins-ci.org/browse/JENKINS-44160" rel="nofollow noreferrer"><code>Post</code> is only supported in declarative pipelines</a>. </p>

<p>You could have a look at their <a href="https://github.com/jenkinsci/kubernetes-plugin/blob/master/examples/declarative.groovy" rel="nofollow noreferrer">declarative example</a> if you absolutely must use <code>post</code>.</p>

<pre><code>pipeline {
  agent {
    kubernetes {
      //cloud 'kubernetes'
      label 'mypod'
      containerTemplate {
        name 'maven'
        image 'maven:3.3.9-jdk-8-alpine'
        ttyEnabled true
        command 'cat'
      }
    }
  }
  stages {
    stage('Run maven') {
      steps {
        container('maven') {
          sh 'mvn -version'
        }
      }
    }
  }
}
</code></pre>
