From 9e69fecf26355b04b050925a2c114abf6e26ea45 Mon Sep 17 00:00:00 2001 From: maxcask Date: Wed, 16 Oct 2024 11:01:06 +0400 Subject: [PATCH 01/10] 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 02/10] 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") } } } From a138c7ed1e3c9520db12fb7b78c538d97b802904 Mon Sep 17 00:00:00 2001 From: maxcask Date: Mon, 18 Nov 2024 13:24:19 +0400 Subject: [PATCH 03/10] add renaming for stage from extension --- vars/piperStageWrapper.groovy | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vars/piperStageWrapper.groovy b/vars/piperStageWrapper.groovy index 1d6f1a3195..b279cb3ff3 100644 --- a/vars/piperStageWrapper.groovy +++ b/vars/piperStageWrapper.groovy @@ -92,6 +92,14 @@ private void stageLocking(Map config, Closure body) { private void executeStage(script, originalStage, stageName, config, utils, telemetryDisabled = false) { boolean projectExtensions boolean globalExtensions + if (stageName == 'Central Build') { + def stages = script.globalPipelineEnvironment.configuration.stages + if (stages != null && (!stages.containsKey('Central Build') || stages.containsKey('Build'))) { + stageName = 'Build' + } else { + stageName = 'Central Build' + } + } def startTime = System.currentTimeMillis() try { From cd1aee28c500289e67e6042397bfc0ef0ad8f02f Mon Sep 17 00:00:00 2001 From: maxcask Date: Mon, 18 Nov 2024 13:42:21 +0400 Subject: [PATCH 04/10] rename after extension is loaded --- vars/piperStageWrapper.groovy | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/vars/piperStageWrapper.groovy b/vars/piperStageWrapper.groovy index b279cb3ff3..ff1d26c7d7 100644 --- a/vars/piperStageWrapper.groovy +++ b/vars/piperStageWrapper.groovy @@ -92,14 +92,7 @@ private void stageLocking(Map config, Closure body) { private void executeStage(script, originalStage, stageName, config, utils, telemetryDisabled = false) { boolean projectExtensions boolean globalExtensions - if (stageName == 'Central Build') { - def stages = script.globalPipelineEnvironment.configuration.stages - if (stages != null && (!stages.containsKey('Central Build') || stages.containsKey('Build'))) { - stageName = 'Build' - } else { - stageName = 'Central Build' - } - } + def startTime = System.currentTimeMillis() try { @@ -115,6 +108,14 @@ private void executeStage(script, originalStage, stageName, config, utils, telem globalExtensions = fileExists(globalInterceptorFile) // Pre-defining the real originalStage in body variable, might be overwritten later if extensions exist def body = originalStage + if (stageName == 'Central Build') { + def stages = script.globalPipelineEnvironment.configuration.stages + if (stages != null && (!stages.containsKey('Central Build') || stages.containsKey('Build'))) { + stageName = 'Build' + } else { + stageName = 'Central Build' + } + } // First, check if a global extension exists via a dedicated repository if (globalExtensions && allowExtensions(script)) { From d084d700d669813c62e87b79ea532c890b8a87b1 Mon Sep 17 00:00:00 2001 From: maxcask Date: Mon, 18 Nov 2024 17:47:11 +0400 Subject: [PATCH 05/10] add verbose --- vars/piperStageWrapper.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/piperStageWrapper.groovy b/vars/piperStageWrapper.groovy index ff1d26c7d7..a0b4106abe 100644 --- a/vars/piperStageWrapper.groovy +++ b/vars/piperStageWrapper.groovy @@ -106,6 +106,7 @@ private void executeStage(script, originalStage, stageName, config, utils, telem def globalInterceptorFile = "${config.globalExtensionsDirectory}${stageName}.groovy" projectExtensions = fileExists(projectInterceptorFile) globalExtensions = fileExists(globalInterceptorFile) + echo "[${STEP_NAME}] Running project interceptor '${projectExtensions}' for ${stageName}." // Pre-defining the real originalStage in body variable, might be overwritten later if extensions exist def body = originalStage if (stageName == 'Central Build') { From 48e15b3d4276ec327dc001e032885b961cdf5711 Mon Sep 17 00:00:00 2001 From: maxcask Date: Mon, 18 Nov 2024 17:54:12 +0400 Subject: [PATCH 06/10] add verbose --- vars/piperStageWrapper.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/piperStageWrapper.groovy b/vars/piperStageWrapper.groovy index a0b4106abe..54ab241e09 100644 --- a/vars/piperStageWrapper.groovy +++ b/vars/piperStageWrapper.groovy @@ -107,6 +107,7 @@ private void executeStage(script, originalStage, stageName, config, utils, telem projectExtensions = fileExists(projectInterceptorFile) globalExtensions = fileExists(globalInterceptorFile) echo "[${STEP_NAME}] Running project interceptor '${projectExtensions}' for ${stageName}." + echo "[${STEP_NAME}] VERBOSE: check allowed extensions '${script.env.PIPER_DISABLE_EXTENSIONS}'" // Pre-defining the real originalStage in body variable, might be overwritten later if extensions exist def body = originalStage if (stageName == 'Central Build') { From 64b41075dd5f388c89dfb153580be0205c82790d Mon Sep 17 00:00:00 2001 From: maxcask Date: Mon, 18 Nov 2024 18:54:51 +0400 Subject: [PATCH 07/10] rename extension file name --- vars/piperStageWrapper.groovy | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/vars/piperStageWrapper.groovy b/vars/piperStageWrapper.groovy index 54ab241e09..ba24a57e62 100644 --- a/vars/piperStageWrapper.groovy +++ b/vars/piperStageWrapper.groovy @@ -104,10 +104,19 @@ private void executeStage(script, originalStage, stageName, config, utils, telem */ def projectInterceptorFile = "${config.projectExtensionsDirectory}${stageName}.groovy" def globalInterceptorFile = "${config.globalExtensionsDirectory}${stageName}.groovy" + /* due to renaming stage 'Central Build' to 'Build' need to get configuration from + extension file name 'Central Build.groovy', once all the users will 'Build' as a stageName, + this reaming should be removed + */ + if (stageName == 'Build'){ + centralBuildExtensionFileName = "Central Build.groovy" + projectInterceptorFile = "${config.projectExtensionsDirectory}${centralBuildExtensionFileName}" + globalInterceptorFile = "${config.globalExtensionsDirectory}${centralBuildExtensionFileName}" + } projectExtensions = fileExists(projectInterceptorFile) globalExtensions = fileExists(globalInterceptorFile) echo "[${STEP_NAME}] Running project interceptor '${projectExtensions}' for ${stageName}." - echo "[${STEP_NAME}] VERBOSE: check allowed extensions '${script.env.PIPER_DISABLE_EXTENSIONS}'" + echo "[${STEP_NAME}] VERBOSE: check allowed extensions '${script.env.PIPER_DISABLE_EXTENSIONS}'" // Pre-defining the real originalStage in body variable, might be overwritten later if extensions exist def body = originalStage if (stageName == 'Central Build') { From 91c3e38cc8e1cb6c51c9bcb900e43d50c2014cbd Mon Sep 17 00:00:00 2001 From: maxcask Date: Mon, 18 Nov 2024 19:14:55 +0400 Subject: [PATCH 08/10] rename extension file name --- vars/piperStageWrapper.groovy | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/vars/piperStageWrapper.groovy b/vars/piperStageWrapper.groovy index ba24a57e62..bb05180914 100644 --- a/vars/piperStageWrapper.groovy +++ b/vars/piperStageWrapper.groovy @@ -105,28 +105,21 @@ private void executeStage(script, originalStage, stageName, config, utils, telem def projectInterceptorFile = "${config.projectExtensionsDirectory}${stageName}.groovy" def globalInterceptorFile = "${config.globalExtensionsDirectory}${stageName}.groovy" /* due to renaming stage 'Central Build' to 'Build' need to get configuration from - extension file name 'Central Build.groovy', once all the users will 'Build' as a stageName, - this reaming should be removed + extension file name 'Central Build.groovy', once all the users will 'Build' as a stageName + and extension filename, below renaming snippet should be removed */ if (stageName == 'Build'){ centralBuildExtensionFileName = "Central Build.groovy" projectInterceptorFile = "${config.projectExtensionsDirectory}${centralBuildExtensionFileName}" globalInterceptorFile = "${config.globalExtensionsDirectory}${centralBuildExtensionFileName}" } + projectExtensions = fileExists(projectInterceptorFile) globalExtensions = fileExists(globalInterceptorFile) echo "[${STEP_NAME}] Running project interceptor '${projectExtensions}' for ${stageName}." echo "[${STEP_NAME}] VERBOSE: check allowed extensions '${script.env.PIPER_DISABLE_EXTENSIONS}'" // Pre-defining the real originalStage in body variable, might be overwritten later if extensions exist def body = originalStage - if (stageName == 'Central Build') { - def stages = script.globalPipelineEnvironment.configuration.stages - if (stages != null && (!stages.containsKey('Central Build') || stages.containsKey('Build'))) { - stageName = 'Build' - } else { - stageName = 'Central Build' - } - } // First, check if a global extension exists via a dedicated repository if (globalExtensions && allowExtensions(script)) { From ecc0a4f96c77360f1b443c475bc79119d6785ea8 Mon Sep 17 00:00:00 2001 From: maxcask Date: Tue, 19 Nov 2024 11:03:09 +0400 Subject: [PATCH 09/10] handle extension filename --- vars/piperStageWrapper.groovy | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vars/piperStageWrapper.groovy b/vars/piperStageWrapper.groovy index bb05180914..8f3046e639 100644 --- a/vars/piperStageWrapper.groovy +++ b/vars/piperStageWrapper.groovy @@ -104,20 +104,20 @@ private void executeStage(script, originalStage, stageName, config, utils, telem */ def projectInterceptorFile = "${config.projectExtensionsDirectory}${stageName}.groovy" def globalInterceptorFile = "${config.globalExtensionsDirectory}${stageName}.groovy" - /* due to renaming stage 'Central Build' to 'Build' need to get configuration from - extension file name 'Central Build.groovy', once all the users will 'Build' as a stageName + /* due to renaming stage 'Central Build' to 'Build' need to define extension file name 'Central Build.groovy' + as stageName used to generate it, once all the users will 'Build' as a stageName and extension filename, below renaming snippet should be removed */ if (stageName == 'Build'){ - centralBuildExtensionFileName = "Central Build.groovy" - projectInterceptorFile = "${config.projectExtensionsDirectory}${centralBuildExtensionFileName}" - globalInterceptorFile = "${config.globalExtensionsDirectory}${centralBuildExtensionFileName}" + if (!fileExists(projectInterceptorFile || !fileExists(globalInterceptorFile){ + def centralBuildExtensionFileName = "Central Build.groovy" + projectInterceptorFile = "${config.projectExtensionsDirectory}${centralBuildExtensionFileName}" + globalInterceptorFile = "${config.globalExtensionsDirectory}${centralBuildExtensionFileName}" + } } projectExtensions = fileExists(projectInterceptorFile) globalExtensions = fileExists(globalInterceptorFile) - echo "[${STEP_NAME}] Running project interceptor '${projectExtensions}' for ${stageName}." - echo "[${STEP_NAME}] VERBOSE: check allowed extensions '${script.env.PIPER_DISABLE_EXTENSIONS}'" // Pre-defining the real originalStage in body variable, might be overwritten later if extensions exist def body = originalStage From f4de71ee66b99939e3804dd0dc8b8efcf01c5b65 Mon Sep 17 00:00:00 2001 From: maxcask Date: Tue, 19 Nov 2024 11:06:08 +0400 Subject: [PATCH 10/10] typo --- vars/piperStageWrapper.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/piperStageWrapper.groovy b/vars/piperStageWrapper.groovy index 8f3046e639..142a89617a 100644 --- a/vars/piperStageWrapper.groovy +++ b/vars/piperStageWrapper.groovy @@ -109,7 +109,7 @@ private void executeStage(script, originalStage, stageName, config, utils, telem and extension filename, below renaming snippet should be removed */ if (stageName == 'Build'){ - if (!fileExists(projectInterceptorFile || !fileExists(globalInterceptorFile){ + if (!fileExists(projectInterceptorFile) || !fileExists(globalInterceptorFile)){ def centralBuildExtensionFileName = "Central Build.groovy" projectInterceptorFile = "${config.projectExtensionsDirectory}${centralBuildExtensionFileName}" globalInterceptorFile = "${config.globalExtensionsDirectory}${centralBuildExtensionFileName}"