2017-12-06 13:03:06 +02:00
|
|
|
package com.sap.piper
|
|
|
|
|
|
|
|
import com.cloudbees.groovy.cps.NonCPS
|
|
|
|
|
2019-01-08 18:35:53 +02:00
|
|
|
@API
|
2017-12-06 13:03:06 +02:00
|
|
|
class ConfigurationLoader implements Serializable {
|
|
|
|
@NonCPS
|
2018-05-04 11:34:51 +02:00
|
|
|
static Map stepConfiguration(script, String stepName) {
|
2017-12-06 13:03:06 +02:00
|
|
|
return loadConfiguration(script, 'steps', stepName, ConfigurationType.CUSTOM_CONFIGURATION)
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonCPS
|
2018-05-04 11:34:51 +02:00
|
|
|
static Map stageConfiguration(script, String stageName) {
|
2017-12-06 13:03:06 +02:00
|
|
|
return loadConfiguration(script, 'stages', stageName, ConfigurationType.CUSTOM_CONFIGURATION)
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonCPS
|
2018-05-04 11:34:51 +02:00
|
|
|
static Map defaultStepConfiguration(script, String stepName) {
|
2017-12-06 13:03:06 +02:00
|
|
|
return loadConfiguration(script, 'steps', stepName, ConfigurationType.DEFAULT_CONFIGURATION)
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonCPS
|
2018-05-04 11:34:51 +02:00
|
|
|
static Map defaultStageConfiguration(script, String stageName) {
|
2017-12-06 13:03:06 +02:00
|
|
|
return loadConfiguration(script, 'stages', stageName, ConfigurationType.DEFAULT_CONFIGURATION)
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonCPS
|
2018-05-04 11:34:51 +02:00
|
|
|
static Map generalConfiguration(script){
|
2017-12-06 13:03:06 +02:00
|
|
|
return script?.commonPipelineEnvironment?.configuration?.general ?: [:]
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonCPS
|
2018-05-04 11:34:51 +02:00
|
|
|
static Map defaultGeneralConfiguration(script){
|
2017-12-06 13:03:06 +02:00
|
|
|
return DefaultValueCache.getInstance()?.getDefaultValues()?.general ?: [:]
|
|
|
|
}
|
|
|
|
|
2018-05-07 10:50:21 +02:00
|
|
|
@NonCPS
|
|
|
|
static Map postActionConfiguration(script, String actionName){
|
|
|
|
return loadConfiguration(script, 'postActions', actionName, ConfigurationType.CUSTOM_CONFIGURATION)
|
|
|
|
}
|
|
|
|
|
2017-12-06 13:03:06 +02:00
|
|
|
@NonCPS
|
2018-05-04 11:34:51 +02:00
|
|
|
private static Map loadConfiguration(script, String type, String entryName, ConfigurationType configType){
|
2017-12-06 13:03:06 +02:00
|
|
|
switch (configType) {
|
|
|
|
case ConfigurationType.CUSTOM_CONFIGURATION:
|
|
|
|
return script?.commonPipelineEnvironment?.configuration?.get(type)?.get(entryName) ?: [:]
|
|
|
|
case ConfigurationType.DEFAULT_CONFIGURATION:
|
|
|
|
return DefaultValueCache.getInstance()?.getDefaultValues()?.get(type)?.get(entryName) ?: [:]
|
|
|
|
default:
|
|
|
|
throw new IllegalArgumentException("Unknown configuration type: ${configType}")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|