1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/vars/handlePipelineStepErrors.groovy

35 lines
1.1 KiB
Groovy
Raw Normal View History

import groovy.text.SimpleTemplateEngine
import groovy.transform.Field
@Field STEP_NAME = 'handlePipelineStepErrors'
2018-08-30 16:33:07 +02:00
void call(Map parameters = [:], body) {
2017-07-11 15:12:03 +02:00
def stepParameters = parameters.stepParameters //mandatory
def stepName = parameters.stepName //mandatory
def verbose = parameters.get('echoDetails', true)
def message = ''
2017-07-11 15:12:03 +02:00
try {
if (stepParameters == null && stepName == null)
error "step handlePipelineStepErrors requires following mandatory parameters: stepParameters, stepName"
if (verbose)
echo "--- BEGIN LIBRARY STEP: ${stepName} ---"
2017-07-11 15:12:03 +02:00
body()
} catch (Throwable err) {
if (verbose)
message += SimpleTemplateEngine.newInstance()
.createTemplate(libraryResource('com.sap.piper/templates/error.log'))
.make([
stepName: stepName,
stepParameters: stepParameters?.toString(),
error: err
]).toString()
2017-07-11 15:12:03 +02:00
throw err
} finally {
if (verbose)
message += "--- END LIBRARY STEP: ${stepName} ---"
echo message
2017-07-11 15:12:03 +02:00
}
}