mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
35ced01ffa
Certain steps should always fail, even though resilience option `failOnError=false` is used. * Docker execution typically happens in another step. We should not hide errors here but rather handle their resilience in the step which uses `dockerExecute` and `dockerExecuteOnKubernetes`. * Wrapper steps like `pipelineExecute`, `pipelineRestartSteps` should not hide errors. If an error occured this has to be considered as **intentional** and not hidden accidentially in case resilience option is switched on.
55 lines
2.0 KiB
Groovy
55 lines
2.0 KiB
Groovy
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
import com.sap.piper.JenkinsUtils
|
|
import com.sap.piper.ConfigurationHelper
|
|
import groovy.transform.Field
|
|
|
|
@Field String STEP_NAME = getClass().getName()
|
|
@Field Set STEP_CONFIG_KEYS = [
|
|
'sendMail',
|
|
'timeoutInSeconds'
|
|
]
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
|
|
|
void call(Map parameters = [:], body) {
|
|
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, failOnError: true) {
|
|
def script = checkScript(this, parameters) ?: this
|
|
def jenkinsUtils = parameters.jenkinsUtilsStub ?: new JenkinsUtils()
|
|
// load default & individual configuration
|
|
Map config = ConfigurationHelper.newInstance(this)
|
|
.loadStepDefaults()
|
|
.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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|