Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-61623

Using post section in kuberenetes agents (kuberenetes-plugin)

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • kubernetes-plugin
    • None
    • latest stable jenkins version
      latest kubernetes-plugin version

      Kubernetes-plugin claims to have integration with declarative pipeline.

      however, picking up the example on the github repo:

      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
      post{
        always{
          sh "echo this is a post step"
        }

      adding the simple post section will not work with the error:

      java.lang.NoSuchMethodError: No such DSL method 'post' found among steps
      

      Analyzing the job logs I see that while it "supports" declarative syntax there is a node call on the run start.

      So from what I believe declarative pipeline is not supported, what is supported is steps declarative syntax.

      This should be clear in the docs, there is no real mention of this anywhere official 

       

       

          [JENKINS-61623] Using post section in kuberenetes agents (kuberenetes-plugin)

          Sami Sallmen added a comment -

          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"
              }
            }
          }
          
          
          

           

           

          Sami Sallmen added a comment - 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" } } }    

            one_random_dev Random Dev
            one_random_dev Random Dev
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: