mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
68 lines
3.0 KiB
Groovy
68 lines
3.0 KiB
Groovy
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
import com.sap.piper.ConfigurationHelper
|
|
import com.sap.piper.ConfigurationLoader
|
|
import com.sap.piper.ConfigurationMerger
|
|
import com.sap.piper.JsonUtils
|
|
import com.sap.piper.Utils
|
|
|
|
import groovy.transform.Field
|
|
|
|
@Field def STEP_NAME = 'influxWriteData'
|
|
|
|
@Field Set GENERAL_CONFIG_KEYS = []
|
|
@Field Set STEP_CONFIG_KEYS = [
|
|
'influxServer',
|
|
'influxPrefix'
|
|
]
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus([
|
|
'artifactVersion'
|
|
])
|
|
|
|
void call(Map parameters = [:]) {
|
|
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters, allowBuildFailure: true) {
|
|
|
|
def script = checkScript(this, parameters)
|
|
if (script == null)
|
|
script = this
|
|
|
|
// load default & individual configuration
|
|
Map configuration = ConfigurationHelper.newInstance(this)
|
|
.loadStepDefaults()
|
|
.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: script.commonPipelineEnvironment.getArtifactVersion()
|
|
])
|
|
.mixin(parameters, PARAMETER_KEYS)
|
|
.use()
|
|
|
|
new Utils().pushToSWA([step: STEP_NAME,
|
|
stepParam1: parameters?.script == null], configuration)
|
|
|
|
if (!configuration.artifactVersion) {
|
|
//this takes care that terminated builds due to milestone-locking do not cause an error
|
|
echo "[${STEP_NAME}] no artifact version available -> exiting writeInflux without writing data"
|
|
return
|
|
}
|
|
|
|
echo """[${STEP_NAME}]----------------------------------------------------------
|
|
Artifact version: ${configuration.artifactVersion}
|
|
Influx server: ${configuration.influxServer}
|
|
Influx prefix: ${configuration.influxPrefix}
|
|
InfluxDB data: ${script.commonPipelineEnvironment.getInfluxCustomData()}
|
|
InfluxDB data map: ${script.commonPipelineEnvironment.getInfluxCustomDataMap()}
|
|
[${STEP_NAME}]----------------------------------------------------------"""
|
|
|
|
if (configuration.influxServer)
|
|
step([$class: 'InfluxDbPublisher', selectedTarget: configuration.influxServer, customPrefix: configuration.influxPrefix, customData: script.commonPipelineEnvironment.getInfluxCustomData(), customDataMap: script.commonPipelineEnvironment.getInfluxCustomDataMap()])
|
|
|
|
//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
|
|
}
|
|
}
|