github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/src/com/sap/piper/ConfigurationLoader.groovy (about)

     1  package com.sap.piper
     2  
     3  @API(deprecated = true)
     4  class ConfigurationLoader implements Serializable {
     5      static Map stepConfiguration(script, String stepName) {
     6          return loadConfiguration(script, 'steps', stepName, ConfigurationType.CUSTOM_CONFIGURATION)
     7      }
     8  
     9      static Map stageConfiguration(script, String stageName) {
    10          return loadConfiguration(script, 'stages', stageName, ConfigurationType.CUSTOM_CONFIGURATION)
    11      }
    12  
    13      static Map defaultStepConfiguration(script, String stepName) {
    14          return loadConfiguration(script, 'steps', stepName, ConfigurationType.DEFAULT_CONFIGURATION)
    15      }
    16  
    17      static Map defaultStageConfiguration(script, String stageName) {
    18          return loadConfiguration(script, 'stages', stageName, ConfigurationType.DEFAULT_CONFIGURATION)
    19      }
    20  
    21      static Map generalConfiguration(script){
    22          try {
    23              return script?.commonPipelineEnvironment?.configuration?.general ?: [:]
    24          } catch (groovy.lang.MissingPropertyException mpe) {
    25              return [:]
    26          }
    27      }
    28  
    29      static Map defaultGeneralConfiguration(script){
    30          return DefaultValueCache.getInstance()?.getDefaultValues()?.general ?: [:]
    31      }
    32  
    33      static Map postActionConfiguration(script, String actionName){
    34          return loadConfiguration(script, 'postActions', actionName, ConfigurationType.CUSTOM_CONFIGURATION)
    35      }
    36  
    37      private static Map loadConfiguration(script, String type, String entryName, ConfigurationType configType){
    38          switch (configType) {
    39              case ConfigurationType.CUSTOM_CONFIGURATION:
    40                  try {
    41                      return script?.commonPipelineEnvironment?.configuration?.get(type)?.get(entryName) ?: [:]
    42                  } catch (groovy.lang.MissingPropertyException mpe) {
    43                      return [:]
    44                  }
    45  
    46              case ConfigurationType.DEFAULT_CONFIGURATION:
    47                  return DefaultValueCache.getInstance()?.getDefaultValues()?.get(type)?.get(entryName) ?: [:]
    48              default:
    49                  throw new IllegalArgumentException("Unknown configuration type: ${configType}")
    50          }
    51      }
    52  }