mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
2e8a9db02c
o The map does not provide access to e.g. sh, echo. o this has the same cpe as property as it is constructed with the current map approach.
51 lines
1.6 KiB
Groovy
51 lines
1.6 KiB
Groovy
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
import com.sap.piper.ConfigurationHelper
|
|
import com.sap.piper.Utils
|
|
import groovy.transform.Field
|
|
|
|
@Field String STEP_NAME = 'healthExecuteCheck'
|
|
@Field Set STEP_CONFIG_KEYS = [
|
|
'healthEndpoint',
|
|
'testServerUrl'
|
|
]
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
|
|
|
void call(Map parameters = [:]) {
|
|
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
|
def script = checkScript(this, parameters) ?: this
|
|
// 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)
|
|
.withMandatoryProperty('testServerUrl')
|
|
.use()
|
|
|
|
new Utils().pushToSWA([step: STEP_NAME], config)
|
|
|
|
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()
|
|
}
|