| It can be confusing as to how to construct a sequence of commands to be executed during a condition, e.g.
pipeline {
postBuild {
success {
sh 'echo Awesome > message'
archive 'message'
sh 'do something else'
}
failure {
sh 'echo Disaster > message'
archive 'message'
sh 'rage something'
}
}
}
What happens if the success archive step fails? Will we "do something else" or will we stop at that point? What happens if the failure archive step fails? Will we "rage something" or will we stop at the failure? The principle of least surprise suggests that we should behave the same way for both. We can argue that the steps in a condition block are actually wrapped steps around the actual steps and that they will be all executed providing the outer condition object holds... that is at least consistent amongst conditions... but it is not consistent with steps or the use of blocks elsewhere. An alternative would be to allow the conditions to be repeated and define the sequence in which conditions are evaluated as being their order of definition, thus
pipeline {
postBuild {
success {
sh 'echo Awesome > message'
}
success {
archive 'message'
}
success {
sh 'do something else'
}
failure {
sh 'echo Disaster > message'
}
failure {
archive 'message'
sh 'rage something'
}
}
}
which clarifies the intent that the three success conditions will only be executed in the event of success being maintained and that the "rage something" will only occur during a failure if the archive step is successful. It also would enable other sequences to be expressed, e.g.:
pipeline {
postBuild {
success {
sh 'echo Awesome > message'
}
failure {
sh 'echo Disaster > message'
}
always {
archive 'message'
}
success {
sh 'do something else'
}
failure {
sh 'rage something'
}
}
}
|