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.

          [JENKINS-41519] Post stages should have well defined order

          Robby Pocase created issue -
          Robby Pocase made changes -
          Description Original: 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.

          {code:Java|title=Jenkinsfile}
          pipeline {
            agent { label 'label' }
            stages {
              stage('stage') {
                steps {
                  echo "stage"
                }
                post {
                  success {
                    echo "Success"
                  }
                  always {
                      echo "Always"
                      //deleteDir()
                  }
                }
              }
            }
          }
          {code}

          {noformat}
          [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
          {noformat}

          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.
          New: 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.
          {code:java|title=Jenkinsfile}
          pipeline {
            agent { label 'label' }
            stages {
              stage('stage') {
                steps {
                  echo "stage"
                }
                post {
                  success {
                    echo "Success"
                  }
                  always {
                      echo "Always"
                      deleteDir()
                  }
                }
              }
            }
          }
          {code}
          {noformat}
          [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
          {noformat}
          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.
          Robby Pocase made changes -
          Description Original: 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.
          {code:java|title=Jenkinsfile}
          pipeline {
            agent { label 'label' }
            stages {
              stage('stage') {
                steps {
                  echo "stage"
                }
                post {
                  success {
                    echo "Success"
                  }
                  always {
                      echo "Always"
                      deleteDir()
                  }
                }
              }
            }
          }
          {code}
          {noformat}
          [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
          {noformat}
          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.
          New: 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.
          {code:java|title=Jenkinsfile}
          pipeline {
            agent { label 'label' }
            stages {
              stage('stage') {
                steps {
                  echo "stage"
                }
                post {
                  success {
                    echo "Success"
                  }
                  always {
                      echo "Always"
                      //deleteDir()
                  }
                }
              }
            }
          }
          {code}
          {noformat}
          [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
          {noformat}
          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.
          James Dumay made changes -
          Epic Link New: JENKINS-45427 [ 183595 ]
          Andrew Bayer made changes -
          Labels New: documentation
          Andrew Bayer made changes -
          Link New: This issue relates to JENKINS-38993 [ JENKINS-38993 ]
          Andrew Bayer made changes -
          Link New: This issue is duplicated by JENKINS-46378 [ JENKINS-46378 ]
          IKO BH made changes -
          Attachment New: image-2018-03-07-10-58-26-892.png [ 41751 ]
          Andrew Bayer made changes -
          Link New: This issue relates to JENKINS-41239 [ JENKINS-41239 ]
          Andrew Bayer made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Fixed but Unreleased [ 10203 ]
          Andrew Bayer made changes -
          Status Original: Fixed but Unreleased [ 10203 ] New: Resolved [ 5 ]

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

              Created:
              Updated:
              Resolved: