2018-09-21 16:55:31 +02:00
|
|
|
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
|
2018-07-03 14:16:17 +02:00
|
|
|
import com.sap.piper.ConfigurationHelper
|
2018-10-08 11:30:42 +02:00
|
|
|
import com.sap.piper.GitUtils
|
2018-08-09 11:35:33 +02:00
|
|
|
import com.sap.piper.Utils
|
2018-07-03 14:16:17 +02:00
|
|
|
import groovy.text.SimpleTemplateEngine
|
2018-10-08 11:30:42 +02:00
|
|
|
import groovy.transform.Field
|
2018-07-03 14:16:17 +02:00
|
|
|
|
|
|
|
@Field String STEP_NAME = 'newmanExecute'
|
2018-10-25 15:44:21 +02:00
|
|
|
|
|
|
|
@Field Set GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS
|
|
|
|
|
2018-07-04 11:12:32 +02:00
|
|
|
@Field Set STEP_CONFIG_KEYS = [
|
|
|
|
'dockerImage',
|
|
|
|
'failOnError',
|
2018-08-08 11:22:08 +02:00
|
|
|
'gitBranch',
|
|
|
|
'gitSshKeyCredentialsId',
|
2018-07-04 11:12:32 +02:00
|
|
|
'newmanCollection',
|
|
|
|
'newmanEnvironment',
|
|
|
|
'newmanGlobals',
|
|
|
|
'newmanRunCommand',
|
2018-08-08 11:22:08 +02:00
|
|
|
'stashContent',
|
2018-07-04 11:12:32 +02:00
|
|
|
'testRepository'
|
|
|
|
]
|
2018-10-25 15:44:21 +02:00
|
|
|
|
2018-07-03 14:16:17 +02:00
|
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
|
|
|
|
2018-08-30 16:33:07 +02:00
|
|
|
void call(Map parameters = [:]) {
|
2018-07-03 14:16:17 +02:00
|
|
|
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
2018-09-21 16:55:31 +02:00
|
|
|
|
2018-10-31 09:40:12 +02:00
|
|
|
def script = checkScript(this, parameters) ?: this
|
2018-09-21 16:55:31 +02:00
|
|
|
|
2018-08-08 11:22:08 +02:00
|
|
|
def utils = parameters?.juStabUtils ?: new Utils()
|
2018-07-03 14:16:17 +02:00
|
|
|
|
|
|
|
// load default & individual configuration
|
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:44:21 +02:00
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
2018-07-03 14:16:17 +02:00
|
|
|
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName?:env.STAGE_NAME, STEP_CONFIG_KEYS)
|
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
|
|
|
.use()
|
|
|
|
|
2018-10-30 17:22:42 +02:00
|
|
|
new Utils().pushToSWA([step: STEP_NAME,
|
2018-11-05 13:33:41 +02:00
|
|
|
stepParam1: parameters?.script == null], config)
|
2018-08-09 11:35:33 +02:00
|
|
|
|
2018-10-08 11:30:42 +02:00
|
|
|
config.stashContent = config.testRepository
|
|
|
|
?[GitUtils.handleTestRepository(this, config)]
|
|
|
|
:utils.unstashAll(config.stashContent)
|
2018-08-08 11:22:08 +02:00
|
|
|
|
2018-07-03 14:16:17 +02:00
|
|
|
List collectionList = findFiles(glob: config.newmanCollection)?.toList()
|
2018-08-08 11:22:08 +02:00
|
|
|
if (collectionList.isEmpty()) {
|
|
|
|
error "[${STEP_NAME}] No collection found with pattern '${config.newmanCollection}'"
|
|
|
|
} else {
|
|
|
|
echo "[${STEP_NAME}] Found files ${collectionList}"
|
|
|
|
}
|
2018-07-03 14:16:17 +02:00
|
|
|
|
2018-08-08 11:22:08 +02:00
|
|
|
dockerExecute(
|
|
|
|
dockerImage: config.dockerImage,
|
|
|
|
stashContent: config.stashContent
|
|
|
|
) {
|
|
|
|
sh 'npm install newman --global --quiet'
|
|
|
|
for(String collection : collectionList){
|
|
|
|
def collectionDisplayName = collection.toString().replace(File.separatorChar,(char)'_').tokenize('.').first()
|
|
|
|
// resolve templates
|
|
|
|
def command = SimpleTemplateEngine.newInstance()
|
|
|
|
.createTemplate(config.newmanRunCommand)
|
|
|
|
.make([
|
|
|
|
config: config.plus([newmanCollection: collection]),
|
|
|
|
collectionDisplayName: collectionDisplayName
|
|
|
|
]).toString()
|
|
|
|
if(!config.failOnError) command += ' --suppress-exit-code'
|
|
|
|
sh "newman ${command}"
|
2018-07-03 14:16:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|