You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-09-16 09:26:22 +02:00
Pr/read project config only if it exists (#959)
* Read the project config only if it exists This avoid trying reading the file and have the control flow based on errors. Beside that it helps troubleshooting when we have some logging (debug level only). * formatting only * Adjust log level
This commit is contained in:
16
cmd/piper.go
16
cmd/piper.go
@@ -8,6 +8,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/SAP/jenkins-library/pkg/config"
|
||||
"github.com/SAP/jenkins-library/pkg/log"
|
||||
"github.com/SAP/jenkins-library/pkg/piperutils"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -78,9 +80,18 @@ func PrepareConfig(cmd *cobra.Command, metadata *config.StepData, stepName strin
|
||||
stepConfig = config.GetStepConfigWithJSON(flagValues, GeneralConfig.StepConfigJSON, filters)
|
||||
} else {
|
||||
// use config & defaults
|
||||
|
||||
var customConfig io.ReadCloser
|
||||
var err error
|
||||
//accept that config file and defaults cannot be loaded since both are not mandatory here
|
||||
customConfig, _ := openFile(GeneralConfig.CustomConfig)
|
||||
if piperutils.FileExists(GeneralConfig.CustomConfig) {
|
||||
if customConfig, err = openFile(GeneralConfig.CustomConfig); err != nil {
|
||||
errors.Wrapf(err, "Cannot read '%s'", GeneralConfig.CustomConfig)
|
||||
}
|
||||
} else {
|
||||
log.Entry().Infof("Project config file '%s' does not exist. No project configuration available.", GeneralConfig.CustomConfig)
|
||||
customConfig = nil
|
||||
}
|
||||
|
||||
var defaultConfig []io.ReadCloser
|
||||
for _, f := range GeneralConfig.DefaultConfig {
|
||||
//ToDo: support also https as source
|
||||
@@ -88,7 +99,6 @@ func PrepareConfig(cmd *cobra.Command, metadata *config.StepData, stepName strin
|
||||
defaultConfig = append(defaultConfig, fc)
|
||||
}
|
||||
|
||||
var err error
|
||||
stepConfig, err = myConfig.GetStepConfig(flagValues, GeneralConfig.ParametersJSON, customConfig, defaultConfig, filters, metadata.Spec.Inputs.Parameters, GeneralConfig.StageName, stepName)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "retrieving step configuration failed")
|
||||
|
@@ -13,8 +13,8 @@ import (
|
||||
)
|
||||
|
||||
type execMockRunner struct {
|
||||
dir []string
|
||||
calls []execCall
|
||||
dir []string
|
||||
calls []execCall
|
||||
shouldFailWith error
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ type execCall struct {
|
||||
}
|
||||
|
||||
type shellMockRunner struct {
|
||||
dir string
|
||||
calls []string
|
||||
dir string
|
||||
calls []string
|
||||
shouldFailWith error
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user