2018-10-24 13:36:30 +02:00
|
|
|
import groovy.text.SimpleTemplateEngine
|
2018-10-09 17:09:55 +02:00
|
|
|
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
|
2018-10-24 13:36:30 +02:00
|
|
|
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"
|
|
|
|
|
2018-10-24 13:36:30 +02:00
|
|
|
if (verbose)
|
|
|
|
echo "--- BEGIN LIBRARY STEP: ${stepName} ---"
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
body()
|
|
|
|
} catch (Throwable err) {
|
2018-10-24 13:36:30 +02:00
|
|
|
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 {
|
2018-10-24 13:36:30 +02:00
|
|
|
if (verbose)
|
|
|
|
message += "--- END LIBRARY STEP: ${stepName} ---"
|
|
|
|
echo message
|
2017-07-11 15:12:03 +02:00
|
|
|
}
|
|
|
|
}
|