From 9e69fecf26355b04b050925a2c114abf6e26ea45 Mon Sep 17 00:00:00 2001 From: maxcask Date: Wed, 16 Oct 2024 11:01:06 +0400 Subject: [PATCH 1/2] add handle stageName --- pkg/config/evaluation.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/config/evaluation.go b/pkg/config/evaluation.go index 1775181a51..55fb91a6ad 100644 --- a/pkg/config/evaluation.go +++ b/pkg/config/evaluation.go @@ -8,6 +8,7 @@ import ( "github.com/pkg/errors" + "github.com/SAP/jenkins-library/pkg/log" "github.com/SAP/jenkins-library/pkg/orchestrator" "github.com/SAP/jenkins-library/pkg/piperutils" ) @@ -49,6 +50,7 @@ func (r *RunConfigV1) evaluateConditionsV1(config *Config, utils piperutils.File continue } + config.handleLegacyStageNaming(stageName) stepConfig, err := r.getStepConfig(config, stageName, step.Name, nil, nil, nil, nil) if err != nil { return err @@ -305,3 +307,20 @@ func anyOtherStepIsActive(targetStep string, runSteps map[string]bool) bool { return false } + +func (c *Config) handleLegacyStageNaming(stageName string) { + currentOrchestrator := orchestrator.DetectOrchestrator().String() + if currentOrchestrator == "Jenkins" && stageName == "Build" { + _, buildExists := c.Stages["Build"] + legacyStageConfig, centralBuildExists := c.Stages["Central Build"] + if buildExists && centralBuildExists { + log.Entry().Warnf("You have 2 entries for build stage in config.yml. Please move steps to the [Build] stage") + return + } + + if centralBuildExists { + c.Stages["Build"] = legacyStageConfig + log.Entry().Warnf("You are using [Central Build] stage inconfig.yml. Please move steps to the [Build] stage") + } + } +} From 1e0839a7a30832ed76ee68ca5fcb16a6c139c8d1 Mon Sep 17 00:00:00 2001 From: Googlom Date: Wed, 16 Oct 2024 12:44:52 +0500 Subject: [PATCH 2/2] some improvements --- pkg/config/evaluation.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/config/evaluation.go b/pkg/config/evaluation.go index 55fb91a6ad..4482a2d296 100644 --- a/pkg/config/evaluation.go +++ b/pkg/config/evaluation.go @@ -40,6 +40,9 @@ func (r *RunConfigV1) evaluateConditionsV1(config *Config, utils piperutils.File // to also consider using the technical name. stageName := stage.DisplayName + // Central Build in Jenkins was renamed to Build. + handleLegacyStageNaming(config, currentOrchestrator, stageName) + // Check #1: Apply explicit activation/deactivation from config file (if any) // and then evaluate stepActive conditions runStep := make(map[string]bool, len(stage.Steps)) @@ -50,7 +53,6 @@ func (r *RunConfigV1) evaluateConditionsV1(config *Config, utils piperutils.File continue } - config.handleLegacyStageNaming(stageName) stepConfig, err := r.getStepConfig(config, stageName, step.Name, nil, nil, nil, nil) if err != nil { return err @@ -308,19 +310,22 @@ func anyOtherStepIsActive(targetStep string, runSteps map[string]bool) bool { return false } -func (c *Config) handleLegacyStageNaming(stageName string) { - currentOrchestrator := orchestrator.DetectOrchestrator().String() - if currentOrchestrator == "Jenkins" && stageName == "Build" { +func handleLegacyStageNaming(c *Config, orchestrator, stageName string) { + if orchestrator == "Jenkins" && stageName == "Build" { _, buildExists := c.Stages["Build"] - legacyStageConfig, centralBuildExists := c.Stages["Central Build"] + centralBuildStageConfig, centralBuildExists := c.Stages["Central Build"] if buildExists && centralBuildExists { - log.Entry().Warnf("You have 2 entries for build stage in config.yml. Please move steps to the [Build] stage") + log.Entry().Warnf("You have 2 entries for build stage in config.yml. " + + "Parameters defined under 'Central Build' are ignored. " + + "Please use only 'Build'") return } if centralBuildExists { - c.Stages["Build"] = legacyStageConfig - log.Entry().Warnf("You are using [Central Build] stage inconfig.yml. Please move steps to the [Build] stage") + c.Stages["Build"] = centralBuildStageConfig + log.Entry().Warnf("You are using 'Central Build' stage in config.yml. " + + "Please move parameters under the 'Build' stage, " + + "since 'Central Build' will be removed in future releases") } } }