2018-10-30 17:49:53 +02:00
|
|
|
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
|
2018-10-18 08:51:48 +02:00
|
|
|
import com.sap.piper.JenkinsUtils
|
|
|
|
import com.sap.piper.ConfigurationHelper
|
|
|
|
import groovy.transform.Field
|
|
|
|
|
2018-11-29 10:54:05 +02:00
|
|
|
@Field String STEP_NAME = getClass().getName()
|
2018-10-18 08:51:48 +02:00
|
|
|
@Field Set STEP_CONFIG_KEYS = [
|
|
|
|
'sendMail',
|
|
|
|
'timeoutInSeconds'
|
|
|
|
]
|
|
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
|
|
|
|
2018-10-18 12:31:14 +02:00
|
|
|
void call(Map parameters = [:], body) {
|
2019-04-08 20:10:54 +02:00
|
|
|
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, failOnError: true) {
|
2018-10-31 09:40:12 +02:00
|
|
|
def script = checkScript(this, parameters) ?: this
|
2018-10-18 08:51:48 +02:00
|
|
|
def jenkinsUtils = parameters.jenkinsUtilsStub ?: new JenkinsUtils()
|
|
|
|
// load default & individual configuration
|
2018-10-18 11:02:09 +02:00
|
|
|
Map config = ConfigurationHelper.newInstance(this)
|
|
|
|
.loadStepDefaults()
|
2018-10-18 08:51:48 +02:00
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
|
|
|
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName?:env.STAGE_NAME, STEP_CONFIG_KEYS)
|
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
|
|
|
.use()
|
|
|
|
|
|
|
|
def restart = true
|
|
|
|
while (restart) {
|
|
|
|
try {
|
|
|
|
body()
|
|
|
|
restart = false
|
|
|
|
} catch (Throwable err) {
|
|
|
|
echo "ERROR occured: ${err}"
|
|
|
|
if (config.sendMail)
|
|
|
|
if (jenkinsUtils.nodeAvailable()) {
|
|
|
|
mailSendNotification script: script, buildResult: 'UNSTABLE'
|
|
|
|
} else {
|
|
|
|
node {
|
|
|
|
mailSendNotification script: script, buildResult: 'UNSTABLE'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
timeout(time: config.timeoutInSeconds, unit: 'SECONDS') {
|
|
|
|
input message: 'Do you want to restart?', ok: 'Restart'
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
restart = false
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|