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-08-15 11:53:28 +02:00
|
|
|
@Field def STEP_NAME = 'influxWriteData'
|
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',
|
|
|
|
'influxPrefix'
|
|
|
|
]
|
|
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus([
|
|
|
|
'artifactVersion'
|
|
|
|
])
|
2018-01-24 10:55:38 +02:00
|
|
|
|
2018-08-15 11:53:28 +02:00
|
|
|
def call(Map parameters = [:]) {
|
|
|
|
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, allowBuildFailure: true) {
|
2018-01-24 10:55:38 +02:00
|
|
|
def script = parameters.script
|
|
|
|
if (script == null)
|
2018-08-15 11:53:28 +02:00
|
|
|
script = [commonPipelineEnvironment: commonPipelineEnvironment]
|
|
|
|
|
|
|
|
// load default & individual configuration
|
|
|
|
Map configuration = ConfigurationHelper
|
|
|
|
.loadStepDefaults(this)
|
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
|
|
|
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName?:env.STAGE_NAME, STEP_CONFIG_KEYS)
|
|
|
|
.mixin([
|
|
|
|
artifactVersion: commonPipelineEnvironment.getArtifactVersion()
|
|
|
|
])
|
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
|
|
|
.use()
|
|
|
|
|
|
|
|
new Utils().pushToSWA([step: STEP_NAME], configuration)
|
|
|
|
|
|
|
|
if (!configuration.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}]----------------------------------------------------------
|
|
|
|
Artifact version: ${configuration.artifactVersion}
|
|
|
|
Influx server: ${configuration.influxServer}
|
|
|
|
Influx prefix: ${configuration.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-08-15 11:53:28 +02:00
|
|
|
if (configuration.influxServer)
|
|
|
|
step([$class: 'InfluxDbPublisher', selectedTarget: configuration.influxServer, customPrefix: configuration.influxPrefix, customData: script.commonPipelineEnvironment.getInfluxCustomData(), customDataMap: script.commonPipelineEnvironment.getInfluxCustomDataMap()])
|
2018-01-24 10:55:38 +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
|
|
|
|
}
|
|
|
|
}
|