mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-04 04:07:16 +02:00
piperPipeline: handle build result correctly (#660)
* add new step buildSetResult * set pipeline result in post stage * exclude buildSetResult from commonStepTests * extend pipeline test * remove post stage reference
This commit is contained in:
parent
bbdb719313
commit
eacec4279d
@ -46,13 +46,14 @@ public class CommonStepsTest extends BasePiperTest{
|
||||
|
||||
// all steps not adopting the usual pattern of working with the script.
|
||||
def whitelistScriptReference = [
|
||||
'commonPipelineEnvironment',
|
||||
'handlePipelineStepErrors',
|
||||
'pipelineExecute',
|
||||
'piperPipeline',
|
||||
'prepareDefaultValues',
|
||||
'setupCommonPipelineEnvironment'
|
||||
]
|
||||
'commonPipelineEnvironment',
|
||||
'handlePipelineStepErrors',
|
||||
'pipelineExecute',
|
||||
'piperPipeline',
|
||||
'prepareDefaultValues',
|
||||
'setupCommonPipelineEnvironment',
|
||||
'buildSetResult'
|
||||
]
|
||||
|
||||
List steps = getSteps().stream()
|
||||
.filter {! whitelistScriptReference.contains(it)}
|
||||
@ -102,17 +103,18 @@ public class CommonStepsTest extends BasePiperTest{
|
||||
}
|
||||
|
||||
private static fieldRelatedWhitelist = [
|
||||
'durationMeasure', // only expects parameters via signature
|
||||
'prepareDefaultValues', // special step (infrastructure)
|
||||
'piperPipeline', // special step (infrastructure)
|
||||
'pipelineStashFilesAfterBuild', // intended to be called from pipelineStashFiles
|
||||
'pipelineStashFilesBeforeBuild', // intended to be called from pipelineStashFiles
|
||||
'pipelineStashFiles', // only forwards to before/after step
|
||||
'pipelineExecute', // special step (infrastructure)
|
||||
'commonPipelineEnvironment', // special step (infrastructure)
|
||||
'handlePipelineStepErrors', // special step (infrastructure)
|
||||
'piperStageWrapper' //intended to be called from within stages
|
||||
]
|
||||
'durationMeasure', // only expects parameters via signature
|
||||
'prepareDefaultValues', // special step (infrastructure)
|
||||
'piperPipeline', // special step (infrastructure)
|
||||
'pipelineStashFilesAfterBuild', // intended to be called from pipelineStashFiles
|
||||
'pipelineStashFilesBeforeBuild', // intended to be called from pipelineStashFiles
|
||||
'pipelineStashFiles', // only forwards to before/after step
|
||||
'pipelineExecute', // special step (infrastructure)
|
||||
'commonPipelineEnvironment', // special step (infrastructure)
|
||||
'handlePipelineStepErrors', // special step (infrastructure)
|
||||
'piperStageWrapper', //intended to be called from within stages
|
||||
'buildSetResult'
|
||||
]
|
||||
|
||||
@Test
|
||||
public void generalConfigKeysSetPresentTest() {
|
||||
@ -170,7 +172,8 @@ public class CommonStepsTest extends BasePiperTest{
|
||||
|
||||
def whitelist = [
|
||||
'commonPipelineEnvironment',
|
||||
'piperPipeline'
|
||||
'piperPipeline',
|
||||
'buildSetResult'
|
||||
]
|
||||
|
||||
def stepsWithWrongStepName = []
|
||||
|
@ -108,8 +108,12 @@ class PiperPipelineTest extends BasePiperTest {
|
||||
})
|
||||
|
||||
helper.registerAllowedMethod('steps', [Closure], null)
|
||||
helper.registerAllowedMethod('post', [Closure], null)
|
||||
helper.registerAllowedMethod('always', [Closure], null)
|
||||
helper.registerAllowedMethod('post', [Closure], {c -> c()})
|
||||
helper.registerAllowedMethod('success', [Closure], {c -> c()})
|
||||
helper.registerAllowedMethod('failure', [Closure], {c -> c()})
|
||||
helper.registerAllowedMethod('aborted', [Closure], {c -> c()})
|
||||
helper.registerAllowedMethod('unstable', [Closure], {c -> c()})
|
||||
helper.registerAllowedMethod('cleanup', [Closure], {c -> c()})
|
||||
|
||||
helper.registerAllowedMethod('input', [Map], {m -> return null})
|
||||
|
||||
|
4
vars/buildSetResult.groovy
Normal file
4
vars/buildSetResult.groovy
Normal file
@ -0,0 +1,4 @@
|
||||
void call(currentBuild, result = 'SUCCESS') {
|
||||
echo "Current build result is ${currentBuild.result}, setting it to ${result}."
|
||||
currentBuild.result = result
|
||||
}
|
@ -81,7 +81,12 @@ void call(parameters) {
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
/* https://jenkins.io/doc/book/pipeline/syntax/#post */
|
||||
success {buildSetResult(currentBuild)}
|
||||
aborted {buildSetResult(currentBuild, 'ABORTED')}
|
||||
failure {buildSetResult(currentBuild, 'FAILURE')}
|
||||
unstable {buildSetResult(currentBuild, 'UNSTABLE')}
|
||||
cleanup {
|
||||
influxWriteData script: parameters.script, wrapInNode: true
|
||||
mailSendNotification script: parameters.script, wrapInNode: true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user