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

Post stages should have well defined order

XMLWordPrintable

      Post stages currently have a defined order in which they run. This limits certain use cases (especially in regards to clean up procedures). It would be nice to be able to specify certain post stages have to run before others.

      Jenkinsfile
      pipeline {
        agent { label 'label' }
        stages {
          stage('stage') {     
            steps {
              echo "stage"
            }
            post {
              success {
                echo "Success"
              }
              always {
                  echo "Always"
                  //deleteDir()
              }
            }
          }
        }
      }
      
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (stage)
      [Pipeline] echo
      stage
      [Pipeline] echo
      Post stage
      [Pipeline] echo
      Always
      [Pipeline] echo
      Success
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      

      In the example Jenkinsfile, I want success to run before always. In my production use case, I want to stash some artifacts for a future stage. The future stage is set up to run on certain conditions, so clean up cannot be delayed.

      How order should be determined is open ended. To me, running in the Jenkinsfile order is more intuitive for a user, but there may be cases where you want to change that.

            abayer Andrew Bayer
            rpocase Robby Pocase
            Votes:
            10 Vote for this issue
            Watchers:
            19 Start watching this issue

              Created:
              Updated:
              Resolved: