1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00

chore: emit used project config & defaults to log (#1633)

* print used project config

* print used project defaults
This commit is contained in:
Christopher Fenner 2020-06-10 09:39:29 +02:00 committed by GitHub
parent 1ee13b358b
commit 8e78199cce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -134,6 +134,8 @@ func PrepareConfig(cmd *cobra.Command, metadata *config.StepData, stepName strin
if len(GeneralConfig.StepConfigJSON) != 0 { if len(GeneralConfig.StepConfigJSON) != 0 {
// ignore config & defaults in favor of passed stepConfigJSON // ignore config & defaults in favor of passed stepConfigJSON
stepConfig = config.GetStepConfigWithJSON(flagValues, GeneralConfig.StepConfigJSON, filters) stepConfig = config.GetStepConfigWithJSON(flagValues, GeneralConfig.StepConfigJSON, filters)
log.Entry().Infof("Project config: passed via JSON")
log.Entry().Infof("Project defaults: passed via JSON")
} else { } else {
// use config & defaults // use config & defaults
var customConfig io.ReadCloser var customConfig io.ReadCloser
@ -141,31 +143,33 @@ func PrepareConfig(cmd *cobra.Command, metadata *config.StepData, stepName strin
//accept that config file and defaults cannot be loaded since both are not mandatory here //accept that config file and defaults cannot be loaded since both are not mandatory here
{ {
projectConfigFile := getProjectConfigFile(GeneralConfig.CustomConfig) projectConfigFile := getProjectConfigFile(GeneralConfig.CustomConfig)
if exists, err := piperutils.FileExists(projectConfigFile); exists {
exists, err := piperutils.FileExists(projectConfigFile) log.Entry().Infof("Project config: '%s'", projectConfigFile)
if exists {
if customConfig, err = openFile(projectConfigFile); err != nil { if customConfig, err = openFile(projectConfigFile); err != nil {
return errors.Wrapf(err, "Cannot read '%s'", projectConfigFile) return errors.Wrapf(err, "Cannot read '%s'", projectConfigFile)
} }
} else { } else {
log.Entry().Infof("Project config file '%s' does not exist. No project configuration available.", projectConfigFile) log.Entry().Infof("Project config: NONE ('%s' does not exist)", projectConfigFile)
customConfig = nil customConfig = nil
} }
} }
var defaultConfig []io.ReadCloser var defaultConfig []io.ReadCloser
for _, f := range GeneralConfig.DefaultConfig { if len(GeneralConfig.DefaultConfig) == 0 {
fc, err := openFile(f) log.Entry().Info("Project defaults: NONE")
}
for _, projectDefaultFile := range GeneralConfig.DefaultConfig {
fc, err := openFile(projectDefaultFile)
// only create error for non-default values // only create error for non-default values
if err != nil && f != ".pipeline/defaults.yaml" { if err != nil {
return errors.Wrapf(err, "config: getting defaults failed: '%v'", f) if projectDefaultFile != ".pipeline/defaults.yaml" {
} log.Entry().Infof("Project defaults: '%s'", projectDefaultFile)
if err == nil { return errors.Wrapf(err, "Cannot read '%s'", projectDefaultFile)
}
} else {
log.Entry().Infof("Project defaults: '%s'", projectDefaultFile)
defaultConfig = append(defaultConfig, fc) defaultConfig = append(defaultConfig, fc)
log.Entry().Infof("Added default config '%s'", f)
} }
} }
stepConfig, err = myConfig.GetStepConfig(flagValues, GeneralConfig.ParametersJSON, customConfig, defaultConfig, GeneralConfig.IgnoreCustomDefaults, filters, metadata.Spec.Inputs.Parameters, metadata.Spec.Inputs.Secrets, resourceParams, GeneralConfig.StageName, stepName, metadata.Metadata.Aliases) stepConfig, err = myConfig.GetStepConfig(flagValues, GeneralConfig.ParametersJSON, customConfig, defaultConfig, GeneralConfig.IgnoreCustomDefaults, filters, metadata.Spec.Inputs.Parameters, metadata.Spec.Inputs.Secrets, resourceParams, GeneralConfig.StageName, stepName, metadata.Metadata.Aliases)
if err != nil { if err != nil {
return errors.Wrap(err, "retrieving step configuration failed") return errors.Wrap(err, "retrieving step configuration failed")