1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-03 15:02:35 +02:00

fix: getting config should also work in case there is no project config (#951)

This commit is contained in:
Marcus Holl 2019-11-06 10:28:15 +01:00 committed by GitHub
parent 58128be970
commit a456282d6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View File

@ -53,9 +53,12 @@ func generateConfig() error {
return errors.Wrap(err, "metadata: read failed") return errors.Wrap(err, "metadata: read failed")
} }
customConfig, err := configOptions.openFile(generalConfig.customConfig) var customConfig io.ReadCloser
if err != nil { if fileExists(generalConfig.customConfig) {
return errors.Wrap(err, "config: open failed") customConfig, err = configOptions.openFile(generalConfig.customConfig)
if err != nil {
return errors.Wrap(err, "config: open failed")
}
} }
defaultConfig, paramFilter, err := defaultsAndFilters(&metadata) defaultConfig, paramFilter, err := defaultsAndFilters(&metadata)
@ -118,3 +121,11 @@ func defaultsAndFilters(metadata *config.StepData) ([]io.ReadCloser, config.Step
//ToDo: retrieve default values from metadata //ToDo: retrieve default values from metadata
return nil, metadata.GetParameterFilters(), nil return nil, metadata.GetParameterFilters(), nil
} }
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}

View File

@ -81,12 +81,9 @@ func (c *Config) GetStepConfig(flagValues map[string]interface{}, paramJSON stri
var stepConfig StepConfig var stepConfig StepConfig
var d PipelineDefaults var d PipelineDefaults
if err := c.ReadConfig(configuration); err != nil { if configuration != nil {
switch err.(type) { if err := c.ReadConfig(configuration); err != nil {
case *ParseError:
return StepConfig{}, errors.Wrap(err, "failed to parse custom pipeline configuration") return StepConfig{}, errors.Wrap(err, "failed to parse custom pipeline configuration")
default:
//ignoring unavailability of config file since considered optional
} }
} }
c.ApplyAliasConfig(parameters, filters, stageName, stepName) c.ApplyAliasConfig(parameters, filters, stageName, stepName)