mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
b7468a7ae4
Having the step name always the same like the file name, which is in turn the class name is redundant.
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 = getClass().getName()
|
|
|
|
@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
|
|
}
|
|
}
|