1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/src/com/sap/piper/ConfigurationLoader.groovy

53 lines
2.1 KiB
Groovy

package com.sap.piper
@API(deprecated = true)
class ConfigurationLoader implements Serializable {
static Map stepConfiguration(script, String stepName) {
return loadConfiguration(script, 'steps', stepName, ConfigurationType.CUSTOM_CONFIGURATION)
}
static Map stageConfiguration(script, String stageName) {
return loadConfiguration(script, 'stages', stageName, ConfigurationType.CUSTOM_CONFIGURATION)
}
static Map defaultStepConfiguration(script, String stepName) {
return loadConfiguration(script, 'steps', stepName, ConfigurationType.DEFAULT_CONFIGURATION)
}
static Map defaultStageConfiguration(script, String stageName) {
return loadConfiguration(script, 'stages', stageName, ConfigurationType.DEFAULT_CONFIGURATION)
}
static Map generalConfiguration(script){
try {
return script?.commonPipelineEnvironment?.configuration?.general ?: [:]
} catch (groovy.lang.MissingPropertyException mpe) {
return [:]
}
}
static Map defaultGeneralConfiguration(script){
return DefaultValueCache.getInstance()?.getDefaultValues()?.general ?: [:]
}
static Map postActionConfiguration(script, String actionName){
return loadConfiguration(script, 'postActions', actionName, ConfigurationType.CUSTOM_CONFIGURATION)
}
private static Map loadConfiguration(script, String type, String entryName, ConfigurationType configType){
switch (configType) {
case ConfigurationType.CUSTOM_CONFIGURATION:
try {
return script?.commonPipelineEnvironment?.configuration?.get(type)?.get(entryName) ?: [:]
} catch (groovy.lang.MissingPropertyException mpe) {
return [:]
}
case ConfigurationType.DEFAULT_CONFIGURATION:
return DefaultValueCache.getInstance()?.getDefaultValues()?.get(type)?.get(entryName) ?: [:]
default:
throw new IllegalArgumentException("Unknown configuration type: ${configType}")
}
}
}