From a456282d6a3f3ed5a6f70615ec6ebcc94287df11 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Wed, 6 Nov 2019 10:28:15 +0100 Subject: [PATCH] fix: getting config should also work in case there is no project config (#951) --- cmd/getConfig.go | 17 ++++++++++++++--- pkg/config/config.go | 7 ++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cmd/getConfig.go b/cmd/getConfig.go index bbc4cc799..edef89618 100644 --- a/cmd/getConfig.go +++ b/cmd/getConfig.go @@ -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() +} diff --git a/pkg/config/config.go b/pkg/config/config.go index 622e9dffb..2ef7f62e2 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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)