The post step in description is not really correct. It works if the post is on the same level as stages-section, a child to pipeline. Like this:
pipeline {
agent {
kubernetes {
yamlFile 'examples/declarative_from_yaml_file/KubernetesPod.yaml'
}
}
stages {
stage('Run maven') {
steps {
sh 'set'
sh "echo OUTSIDE_CONTAINER_ENV_VAR = ${CONTAINER_ENV_VAR}"
container('maven') {
sh 'echo MAVEN_CONTAINER_ENV_VAR = ${CONTAINER_ENV_VAR}'
sh 'mvn -version'
}
container('busybox') {
sh 'echo BUSYBOX_CONTAINER_ENV_VAR = ${CONTAINER_ENV_VAR}'
sh '/bin/busybox'
}
}
}
}
// simply adding a basic post step inside the pipeline
post {
always {
sh "echo this is a post step"
}
}
}