-
Improvement
-
Resolution: Fixed
-
Major
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.
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.
- is duplicated by
-
JENKINS-46378 Pipeline Model Definition Post Action Order
-
- Closed
-
- relates to
-
JENKINS-41239 Error during always block skips execution of remaining steps
-
- Closed
-
-
JENKINS-38993 Deterministic order of build condition block execution in Declarative
-
- Closed
-
I think I have something that may help with this over in a PR for
JENKINS-41239- a new post condition, currently called cleanup (because I couldn't call it finally due to that being a reserved word in Groovy), which is like always (as in it'll run regardless of build status), but it runs after all other post conditions. So with this, always is the first post condition to run, and cleanup is the last, regardless of build status. So you can do things like deleteDir() etc in cleanup without problems.Does that sound like it'd do the trick here?