2018-09-21 16:55:31 +02:00
|
|
|
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
|
2018-08-15 11:53:28 +02:00
|
|
|
import com.sap.piper.ConfigurationHelper
|
2018-01-24 10:55:38 +02:00
|
|
|
import com.sap.piper.ConfigurationLoader
|
|
|
|
import com.sap.piper.ConfigurationMerger
|
|
|
|
import com.sap.piper.JsonUtils
|
2018-08-15 11:53:28 +02:00
|
|
|
import com.sap.piper.Utils
|
2018-01-24 10:55:38 +02:00
|
|
|
|
2018-08-15 11:53:28 +02:00
|
|
|
import groovy.transform.Field
|
2018-01-24 10:55:38 +02:00
|
|
|
|
2018-11-29 10:54:05 +02:00
|
|
|
@Field def STEP_NAME = getClass().getName()
|
2018-01-24 10:55:38 +02:00
|
|
|
|
2018-08-15 11:53:28 +02:00
|
|
|
@Field Set GENERAL_CONFIG_KEYS = []
|
|
|
|
@Field Set STEP_CONFIG_KEYS = [
|
|
|
|
'influxServer',
|
2018-12-12 18:33:36 +02:00
|
|
|
'influxPrefix',
|
|
|
|
'wrapInNode'
|
2018-08-15 11:53:28 +02:00
|
|
|
]
|
|
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus([
|
|
|
|
'artifactVersion'
|
|
|
|
])
|
2018-01-24 10:55:38 +02:00
|
|
|
|
2018-08-30 16:33:07 +02:00
|
|
|
void call(Map parameters = [:]) {
|
2018-08-15 11:53:28 +02:00
|
|
|
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, allowBuildFailure: true) {
|
2018-09-21 16:55:31 +02:00
|
|
|
|
|
|
|
def script = checkScript(this, parameters)
|
2018-01-24 10:55:38 +02:00
|
|
|
if (script == null)
|
2018-11-05 13:26:48 +02:00
|
|
|
script = this
|
2018-08-15 11:53:28 +02:00
|
|
|
|
|
|
|
// load default & individual configuration
|
2018-12-12 18:33:36 +02:00
|
|
|
Map config = ConfigurationHelper.newInstance(this)
|
2018-09-07 10:08:16 +02:00
|
|
|
.loadStepDefaults()
|
2018-08-15 11:53:28 +02:00
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
|
|
|
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName?:env.STAGE_NAME, STEP_CONFIG_KEYS)
|
|
|
|
.mixin([
|
2018-11-07 12:37:18 +02:00
|
|
|
artifactVersion: script.commonPipelineEnvironment.getArtifactVersion()
|
2018-08-15 11:53:28 +02:00
|
|
|
])
|
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
|
|
|
.use()
|
|
|
|
|
2018-10-30 17:22:42 +02:00
|
|
|
new Utils().pushToSWA([step: STEP_NAME,
|
2018-12-12 18:33:36 +02:00
|
|
|
stepParam1: parameters?.script == null], config)
|
2018-08-15 11:53:28 +02:00
|
|
|
|
2018-12-12 18:33:36 +02:00
|
|
|
if (!config.artifactVersion) {
|
2018-01-24 10:55:38 +02:00
|
|
|
//this takes care that terminated builds due to milestone-locking do not cause an error
|
2018-08-15 11:53:28 +02:00
|
|
|
echo "[${STEP_NAME}] no artifact version available -> exiting writeInflux without writing data"
|
2018-01-24 10:55:38 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-15 11:53:28 +02:00
|
|
|
echo """[${STEP_NAME}]----------------------------------------------------------
|
2018-12-12 18:33:36 +02:00
|
|
|
Artifact version: ${config.artifactVersion}
|
|
|
|
Influx server: ${config.influxServer}
|
|
|
|
Influx prefix: ${config.influxPrefix}
|
2018-01-24 10:55:38 +02:00
|
|
|
InfluxDB data: ${script.commonPipelineEnvironment.getInfluxCustomData()}
|
|
|
|
InfluxDB data map: ${script.commonPipelineEnvironment.getInfluxCustomDataMap()}
|
2018-08-15 11:53:28 +02:00
|
|
|
[${STEP_NAME}]----------------------------------------------------------"""
|
2018-01-24 10:55:38 +02:00
|
|
|
|
2018-12-12 18:33:36 +02:00
|
|
|
if(config.wrapInNode){
|
|
|
|
node(''){
|
|
|
|
try{
|
|
|
|
writeToInflux(config, script)
|
|
|
|
}finally{
|
|
|
|
deleteDir()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
writeToInflux(config, script)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-24 10:55:38 +02:00
|
|
|
|
2018-12-12 18:33:36 +02:00
|
|
|
private void writeToInflux(config, script){
|
|
|
|
if (config.influxServer) {
|
|
|
|
step([
|
|
|
|
$class: 'InfluxDbPublisher',
|
|
|
|
selectedTarget: config.influxServer,
|
|
|
|
customPrefix: config.influxPrefix,
|
|
|
|
customData: script.commonPipelineEnvironment.getInfluxCustomData(),
|
|
|
|
customDataMap: script.commonPipelineEnvironment.getInfluxCustomDataMap()
|
|
|
|
])
|
2018-01-24 10:55:38 +02:00
|
|
|
}
|
2018-12-12 18:33:36 +02:00
|
|
|
|
|
|
|
//write results into json file for archiving - also benefitial when no InfluxDB is available yet
|
|
|
|
def jsonUtils = new JsonUtils()
|
|
|
|
writeFile file: 'jenkins_data.json', text: jsonUtils.getPrettyJsonString(script.commonPipelineEnvironment.getInfluxCustomData())
|
|
|
|
writeFile file: 'pipeline_data.json', text: jsonUtils.getPrettyJsonString(script.commonPipelineEnvironment.getInfluxCustomDataMap())
|
|
|
|
archiveArtifacts artifacts: '*data.json', allowEmptyArchive: true
|
|
|
|
|
2018-01-24 10:55:38 +02:00
|
|
|
}
|