1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +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")
}
customConfig, err := configOptions.openFile(generalConfig.customConfig)
if err != nil {
return errors.Wrap(err, "config: open failed")
var customConfig io.ReadCloser
if fileExists(generalConfig.customConfig) {
customConfig, err = configOptions.openFile(generalConfig.customConfig)
if err != nil {
return errors.Wrap(err, "config: open failed")
}
}
defaultConfig, paramFilter, err := defaultsAndFilters(&metadata)
@ -118,3 +121,11 @@ func defaultsAndFilters(metadata *config.StepData) ([]io.ReadCloser, config.Step
//ToDo: retrieve default values from metadata
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 d PipelineDefaults
if err := c.ReadConfig(configuration); err != nil {
switch err.(type) {
case *ParseError:
if configuration != nil {
if err := c.ReadConfig(configuration); err != nil {
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)