2018-09-21 16:55:31 +02:00
|
|
|
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
|
2018-08-15 11:41:01 +02:00
|
|
|
import com.sap.piper.ConfigurationHelper
|
2018-10-08 11:30:42 +02:00
|
|
|
import com.sap.piper.GitUtils
|
|
|
|
import com.sap.piper.Utils
|
2018-08-15 11:41:01 +02:00
|
|
|
import groovy.text.SimpleTemplateEngine
|
|
|
|
import groovy.transform.Field
|
|
|
|
|
2018-11-29 10:54:05 +02:00
|
|
|
@Field String STEP_NAME = getClass().getName()
|
2018-10-25 15:00:11 +02:00
|
|
|
|
|
|
|
@Field Set GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS
|
|
|
|
|
2018-08-15 11:41:01 +02:00
|
|
|
@Field Set STEP_CONFIG_KEYS = [
|
2018-10-08 11:30:42 +02:00
|
|
|
'dockerImage',
|
2018-08-15 11:41:01 +02:00
|
|
|
'dockerWorkspace',
|
|
|
|
'envVars',
|
|
|
|
'failOnError',
|
|
|
|
'gitBranch',
|
|
|
|
'gitSshKeyCredentialsId',
|
|
|
|
'outputFormat',
|
|
|
|
'repository',
|
|
|
|
'stashContent',
|
|
|
|
'testPackage',
|
|
|
|
'testPath',
|
|
|
|
'testRepository'
|
|
|
|
]
|
2018-10-25 15:00:11 +02:00
|
|
|
|
2018-08-15 11:41:01 +02:00
|
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
|
|
|
|
2018-08-30 16:33:07 +02:00
|
|
|
void call(Map parameters = [:]) {
|
2018-08-15 11:41:01 +02:00
|
|
|
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
|
|
|
|
|
|
|
|
def utils = parameters.juStabUtils ?: new Utils()
|
2018-09-21 16:55:31 +02:00
|
|
|
|
2018-10-31 09:40:12 +02:00
|
|
|
def script = checkScript(this, parameters) ?: this
|
2018-08-15 11:41:01 +02:00
|
|
|
|
2018-10-17 11:05:20 +02:00
|
|
|
Map config = ConfigurationHelper.newInstance(this)
|
2018-09-07 10:08:16 +02:00
|
|
|
.loadStepDefaults()
|
2018-10-25 15:00:11 +02:00
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
2018-08-15 11:41:01 +02:00
|
|
|
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName?:env.STAGE_NAME, STEP_CONFIG_KEYS)
|
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
|
|
|
.use()
|
|
|
|
|
|
|
|
// report to SWA
|
2019-01-21 09:47:34 +02:00
|
|
|
utils.pushToSWA([
|
|
|
|
step: STEP_NAME,
|
|
|
|
stepParamKey1: 'scriptMissing',
|
|
|
|
stepParam1: parameters?.script == null
|
|
|
|
], config)
|
2018-08-15 11:41:01 +02:00
|
|
|
|
|
|
|
script.commonPipelineEnvironment.setInfluxStepData('bats', false)
|
|
|
|
|
2018-10-08 11:30:42 +02:00
|
|
|
config.stashContent = config.testRepository
|
|
|
|
?[GitUtils.handleTestRepository(this, config)]
|
|
|
|
:utils.unstashAll(config.stashContent)
|
2018-08-15 11:41:01 +02:00
|
|
|
|
|
|
|
//resolve commonPipelineEnvironment references in envVars
|
|
|
|
config.envVarList = []
|
|
|
|
config.envVars.each {e ->
|
|
|
|
def envValue = SimpleTemplateEngine.newInstance().createTemplate(e.getValue()).make(commonPipelineEnvironment: script.commonPipelineEnvironment).toString()
|
|
|
|
config.envVarList.add("${e.getKey()}=${envValue}")
|
|
|
|
}
|
|
|
|
|
|
|
|
withEnv(config.envVarList) {
|
|
|
|
sh "git clone ${config.repository}"
|
|
|
|
try {
|
|
|
|
sh "bats-core/bin/bats --recursive --tap ${config.testPath} > 'TEST-${config.testPackage}.tap'"
|
|
|
|
script.commonPipelineEnvironment.setInfluxStepData('bats', true)
|
|
|
|
} catch (err) {
|
|
|
|
echo "[${STEP_NAME}] One or more tests failed"
|
|
|
|
if (config.failOnError) throw err
|
|
|
|
} finally {
|
|
|
|
sh "cat 'TEST-${config.testPackage}.tap'"
|
|
|
|
if (config.outputFormat == 'junit') {
|
2018-11-28 11:46:47 +02:00
|
|
|
dockerExecute(script: script, dockerImage: config.dockerImage, dockerWorkspace: config.dockerWorkspace, stashContent: config.stashContent) {
|
2018-08-15 11:41:01 +02:00
|
|
|
sh "npm install tap-xunit -g"
|
|
|
|
sh "cat 'TEST-${config.testPackage}.tap' | tap-xunit --package='${config.testPackage}' > TEST-${config.testPackage}.xml"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|