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

declarative pipeline post do not execute in agent

XMLWordPrintable

      How can pipeline 'post' stages be executed in the pipeline agent environment?

      In the below, the deleteDir() is executing outside the dockerfile defined container, thus not as root, and will fail to remove any files that were generated inside the container as root.

      It appears by default that the post for a specific stage execute in the current agent for that stage, which might be the pipeline agent, but that by default post for the while pipeline execute in a 'none' environment. Is there a method to specify the agent for the whole pipeline post?

       

      pipeline {
          agent {
              dockerfile { args '-u root'}
          }
          stages {
              stage('One') {
                  steps {
                      echo 'Do some stuff as root that produce root owned files in workspace'
                  }
              }
              stage('Two') {
                  steps {
                      echo 'Do some more stuff'
                  }
                  post {
                      always {
                          echo 'Do some stage specific cleanup' # Executed in the pipeline agent
                      }
                  }
              } 
          } 
          post { 
              always {
                  deleteDir() # This is not executed in the pipeline agent context
              }
          }
      }

            Unassigned Unassigned
            nickbrown Nicholas Brown
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: