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

Post stages should have well defined order

    XMLWordPrintable

    Details

    • Epic Link:
    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            Hide
            stefanthurnherr Stefan Thurnherr added a comment -

            Andrew Bayer +1 for the cleanup condition, would solve this issue for us since we mostly want to delete workspace

            Show
            stefanthurnherr Stefan Thurnherr added a comment - Andrew Bayer +1 for the cleanup condition, would solve this issue for us since we mostly want to delete workspace
            Hide
            ericnelson Eric Nelson added a comment -

            Andrew Bayer +1 for cleanup here as well. Solves the issue in most use cases I had in mind.  Thanks! 

            Show
            ericnelson Eric Nelson added a comment - Andrew Bayer +1 for cleanup here as well. Solves the issue in most use cases I had in mind.  Thanks! 
            Hide
            fnasser Fernando Nasser added a comment -

            Caught by surprise with always not being the last one (it is sort of equivalent to the java finally which runs last, for the same cleanup reasons brought up in several JIRAs).  But cleanup would work around that (/me still prefers always being last).

            Do we have a JIRA for the 'cleanup' addition yet?  Could not find with JIRA search as the word is too common.

            Show
            fnasser Fernando Nasser added a comment - Caught by surprise with always not being the last one (it is sort of equivalent to the java finally which runs last, for the same cleanup reasons brought up in several JIRAs).  But cleanup would work around that (/me still prefers always being last). Do we have a JIRA for the 'cleanup' addition yet?  Could not find with JIRA search as the word is too common.
            Hide
            stefanthurnherr Stefan Thurnherr added a comment -

            Fernando Nasser Have you read the earlier comments in this jira issue? You'll find the jira issue for the 'cleanup' addition in Andrew's comment

            Show
            stefanthurnherr Stefan Thurnherr added a comment - Fernando Nasser Have you read the earlier comments in this jira issue? You'll find the jira issue for the 'cleanup' addition in Andrew's comment
            Hide
            fnasser Fernando Nasser added a comment -

            Thanks Stefan, not sure how I missed the JENKINS-41239 one.

             

            Show
            fnasser Fernando Nasser added a comment - Thanks Stefan, not sure how I missed the  JENKINS-41239 one.  

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                rpocase Robby Pocase
              • Votes:
                10 Vote for this issue
                Watchers:
                18 Start watching this issue

                Dates

                • Created:
                  Updated: