mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
Provide configuration layer for custom configuration
This commit is contained in:
parent
0935d766a6
commit
bb811afa41
@ -5,10 +5,15 @@ import com.cloudbees.groovy.cps.NonCPS
|
||||
class DefaultValueCache implements Serializable {
|
||||
private static DefaultValueCache instance
|
||||
|
||||
// Contains defaults values provided by this library itself
|
||||
private Map defaultValues
|
||||
|
||||
private DefaultValueCache(Map defaultValues){
|
||||
// intended for describing e.g. the system landscape on customer side
|
||||
private Map customDefaultValues
|
||||
|
||||
private DefaultValueCache(Map customeDefaultValues, Map customDefaultValues){
|
||||
this.defaultValues = defaultValues
|
||||
this.customDefaultValues = customDefaultValues ?: [:]
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
@ -16,8 +21,8 @@ class DefaultValueCache implements Serializable {
|
||||
return instance
|
||||
}
|
||||
|
||||
static createInstance(Map defaultValues){
|
||||
instance = new DefaultValueCache(defaultValues)
|
||||
static createInstance(Map defaultValues, Map customDefaultValues){
|
||||
instance = new DefaultValueCache(defaultValues, customDefaultValues)
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
@ -25,6 +30,11 @@ class DefaultValueCache implements Serializable {
|
||||
return defaultValues
|
||||
}
|
||||
|
||||
@NonCPS
|
||||
Map getCustomDefaultValues(){
|
||||
return customDefaultValues
|
||||
}
|
||||
|
||||
static reset(){
|
||||
instance = null
|
||||
}
|
||||
|
@ -1,10 +1,26 @@
|
||||
import com.sap.piper.DefaultValueCache
|
||||
|
||||
import hudson.AbortException
|
||||
|
||||
def call(Map parameters = [:]) {
|
||||
handlePipelineStepErrors (stepName: 'prepareDefaultValues', stepParameters: parameters) {
|
||||
if(!DefaultValueCache.getInstance()) {
|
||||
Map defaultValues = readYaml text: libraryResource('default_pipeline_environment.yml')
|
||||
DefaultValueCache.createInstance(defaultValues)
|
||||
Map customDefaultValues = null
|
||||
|
||||
def customDefaults = null
|
||||
|
||||
try {
|
||||
customDefaults = libraryResource('pipeline_environment.yml')
|
||||
} catch(AbortException e) {
|
||||
// custom defaults file not found, that's OK the file is optional.
|
||||
}
|
||||
|
||||
if( customDefaults) {
|
||||
customDefaultValues = readYaml text: customDefaults
|
||||
}
|
||||
echo "CUSTOM_DEFAULT_VALUES: '${customDefaultValues}'."
|
||||
DefaultValueCache.createInstance(defaultValues, customDefaultValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user