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

Declarative pipeline: post section doesn't play nice with agent none

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Hi, so using the declarative pipeline it appears if you have agent none set at the top of the pipeline and agents defined per stage, you are unable to have a post section that executes certain steps (that require a node context). The following will result in an error::

      pipeline {
          agent none
          stages {
              stage('Example') {
                  steps {
                      echo 'Hello World'
                  }
              }
          }
          post { 
              always { 
                  deleteDir()
              }
          }
      }
      
      Required context class hudson.FilePath is missing
      Perhaps you forgot to surround the code with a step that provides this, such as: node
      
      ERROR: Attempted to execute a step that requires a node context while agent none was specified. Be sure to specify your own node { ... } blocks when using agent none.

      I'm guessing its expected behavior but would it be possible to associate an agent with the post section as we do with stages?

      Thanks, David

       

        Attachments

          Issue Links

            Activity

            Hide
            kfox1111 Kevin Fox added a comment -

            Interesting. How do you specify an agent section so that you can run it within a container on the node?

            Show
            kfox1111 Kevin Fox added a comment - Interesting. How do you specify an agent section so that you can run it within a container on the node?
            Hide
            xitrium Sean Talts added a comment - - edited

            Maybe the scripted pipeline version would work, something like

             
            node {
                /* Requires the Docker Pipeline plugin to be installed */
                docker.image('node:7-alpine').inside {
                    stage('Test') {
                        sh 'node --version'
                    }
                }
            }

             
            from pressing "Toggle scripted pipeline (Advanced)" on this page: https://jenkins.io/doc/book/pipeline/docker/

            Show
            xitrium Sean Talts added a comment - - edited Maybe the scripted pipeline version would work, something like   node { /* Requires the Docker Pipeline plugin to be installed */ docker.image( 'node:7-alpine' ).inside { stage( 'Test' ) { sh 'node --version' } } }   from pressing "Toggle scripted pipeline (Advanced)" on this page:  https://jenkins.io/doc/book/pipeline/docker/
            Hide
            kfox1111 Kevin Fox added a comment -

            tried with step and without. something like:

            post {
            always {
            node('docker') {
            docker.image("kfox1111/kubeclient:2018-08-29-1").inside {
            sh 'ls /'

             

            WorkflowScript: 62: Expected a symbol @ line 62, column 17.
            docker.image("kfox1111/kubeclient:2018-08-29-1").inside {

            Not liking something there.

             

            Show
            kfox1111 Kevin Fox added a comment - tried with step and without. something like: post { always { node('docker') { docker.image("kfox1111/kubeclient:2018-08-29-1").inside { sh 'ls /'   WorkflowScript: 62: Expected a symbol @ line 62, column 17. docker.image("kfox1111/kubeclient:2018-08-29-1").inside { Not liking something there.  
            Hide
            kfox1111 Kevin Fox added a comment -

            This looks like it does the trick:

            post {
            always {
            node('docker') {
            script {
            docker.image("kfox1111/kubeclient:2018-08-29-1").inside {

            Show
            kfox1111 Kevin Fox added a comment - This looks like it does the trick: post { always { node('docker') { script { docker.image("kfox1111/kubeclient:2018-08-29-1").inside {
            Hide
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

            Show
            bitwiseman Liam Newman added a comment - Bulk closing resolved issues.

              People

              Assignee:
              abayer Andrew Bayer
              Reporter:
              davidshepard77 david shepard
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: