2018-10-30 17:49:53 +02:00
|
|
|
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
|
2018-10-12 16:06:41 +02:00
|
|
|
import com.sap.piper.ConfigurationHelper
|
2018-10-15 14:18:47 +02:00
|
|
|
import com.sap.piper.Utils
|
2018-10-12 16:06:41 +02:00
|
|
|
import groovy.transform.Field
|
|
|
|
|
|
|
|
@Field String STEP_NAME = 'healthExecuteCheck'
|
2018-10-25 13:52:56 +02:00
|
|
|
|
|
|
|
@Field Set GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS
|
|
|
|
|
2018-10-12 16:06:41 +02:00
|
|
|
@Field Set STEP_CONFIG_KEYS = [
|
2018-10-15 14:18:47 +02:00
|
|
|
'healthEndpoint',
|
2018-10-12 16:06:41 +02:00
|
|
|
'testServerUrl'
|
|
|
|
]
|
2018-10-25 13:52:56 +02:00
|
|
|
|
2018-10-12 16:06:41 +02:00
|
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
|
|
|
|
|
|
|
void call(Map parameters = [:]) {
|
|
|
|
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
2018-10-31 09:40:12 +02:00
|
|
|
def script = checkScript(this, parameters) ?: this
|
2018-10-12 16:06:41 +02:00
|
|
|
// load default & individual configuration
|
2018-10-18 11:02:09 +02:00
|
|
|
Map config = ConfigurationHelper.newInstance(this)
|
|
|
|
.loadStepDefaults()
|
2018-10-25 13:52:56 +02:00
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
2018-10-12 16:06:41 +02:00
|
|
|
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName?:env.STAGE_NAME, STEP_CONFIG_KEYS)
|
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
|
|
|
.withMandatoryProperty('testServerUrl')
|
|
|
|
.use()
|
|
|
|
|
2018-10-15 14:18:47 +02:00
|
|
|
new Utils().pushToSWA([step: STEP_NAME], config)
|
|
|
|
|
2018-10-12 16:06:41 +02:00
|
|
|
def checkUrl = config.testServerUrl
|
|
|
|
if(config.healthEndpoint){
|
|
|
|
if(!checkUrl.endsWith('/'))
|
|
|
|
checkUrl += '/'
|
|
|
|
checkUrl += config.healthEndpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
def statusCode = curl(checkUrl)
|
|
|
|
if (statusCode != '200') {
|
|
|
|
error "Health check failed: ${statusCode}"
|
|
|
|
} else {
|
|
|
|
echo "Health check for ${checkUrl} successful"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def curl(url){
|
|
|
|
return sh(
|
|
|
|
returnStdout: true,
|
|
|
|
script: "curl -so /dev/null -w '%{response_code}' ${url}"
|
|
|
|
).trim()
|
|
|
|
}
|