-
Bug
-
Resolution: Unresolved
-
Blocker
-
None
The declarative pipeline documentation on "post" says the following: "These condition blocks allow the execution of steps inside each condition depending on the completion status of the Pipeline or stage"
Currently, the post execution of a stage seems to refer to the whole pipeline status at that point and not the completion status of the stage as documented.
Given the following pipeline:
pipeline {
agent any
stages {
stage('First') {
steps { echo 'Hello' }
post { success { echo 'First stage is success' } }
}
stage('Second') {
steps { sh """ echo '<testsuite errors="1" failures="0" name="test" skipped="0" tests="1" time="1"><testcase classname="" file="file.txt" name="name" time="0.000"><error message="error"></error></testcase></testsuite>' > test-results.xml """ }
post {
always { junit 'test-results.xml' }
unstable { echo 'Second stage is unstable' }
}
}
stage('Third') {
steps { echo 'Hello' }
post {
success { echo 'Third stage is success' }
unstable { echo 'Third stage is unstable! really???' }
}
}
}
post { unstable { echo 'Job is unstable' } }
}
I get the following output:
[Pipeline] {
[Pipeline] stage
[Pipeline] { (First)
[Pipeline] echo
Hello
Post stage
[Pipeline] echo
First stage is success
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Second)
[Pipeline] sh
+ echo <testsuite errors="1" failures="0" name="test" skipped="0" tests="1" time="1"><testcase classname="" file="file.txt" name="name" time="0.000"><error message="error"></error></testcase></testsuite>
Post stage
[Pipeline] junit
Recording test results
[Pipeline] echo
Second stage is unstable
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Third)
[Pipeline] echo
Hello
Post stage
[Pipeline] echo
Third stage is unstable! really???
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] echo
Job is unstable
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Clearly the third stage post unstable block is executed even though the stage itself is a success.
This is also contradicted by the blue ocean stage view:

- is caused by
-
JENKINS-37792 Pipeline Config: Notifications per stage
-
- Closed
-
- is duplicated by
-
JENKINS-61405 Stage post conditions doomed by build result becoming unstable
-
- Open
-
-
JENKINS-68281 Stage result not always considered for stage post action
-
- Resolved
-
- relates to
-
JENKINS-68288 Object context in BuildCondition.meetsCondition is sometimes a Stage instance, which is not recognized by BuildCondition.getCombinedResult
-
- Open
-
-
JENKINS-39203 All stages show up as UNSTABLE when only one stage should
-
- Resolved
-
-
JENKINS-72059 quality gate setting to only set stage to unstable except of whole build
-
- Resolved
-
- links to