From 2b2c4419496fefbbe48b83cafb90cb7a637ba3fd Mon Sep 17 00:00:00 2001 From: Googlom <36107508+Googlom@users.noreply.github.com> Date: Wed, 10 Jan 2024 14:39:29 +0500 Subject: [PATCH] fix: handle legacy stage name differences (#4733) * add name difference handler function * add conditions for setting keys --------- Co-authored-by: Gulom Alimov Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> --- vars/piperInitRunStageConfiguration.groovy | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/vars/piperInitRunStageConfiguration.groovy b/vars/piperInitRunStageConfiguration.groovy index 6e8f5a7682..b27d978f53 100644 --- a/vars/piperInitRunStageConfiguration.groovy +++ b/vars/piperInitRunStageConfiguration.groovy @@ -39,7 +39,6 @@ import groovy.transform.Field @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS void call(Map parameters = [:]) { - def script = checkScript(this, parameters) ?: this String stageName = parameters.stageName ?: env.STAGE_NAME @@ -74,6 +73,9 @@ void call(Map parameters = [:]) { if (stepsJSONObject) { script.commonPipelineEnvironment.configuration.runStep = new LinkedHashMap(stepsJSONObject) } + + handleRenamedStages(script) + // Retaining this groovy code as some additional checks for activating-deactivating a stage seems to be done. script.commonPipelineEnvironment.configuration.runStage.each {stage -> String currentStage = stage.getKey() @@ -118,3 +120,27 @@ private static boolean checkExtensionExists(Script script, Map config, String st def globalInterceptorFile = "${config.globalExtensionsDirectory}${stageName}.groovy" return script.fileExists(projectInterceptorFile) || script.fileExists(globalInterceptorFile) } + +/** + Before syncing the piper-stage-config.yml file, there were differences in the display names of some stages. + This function duplicates the runStage and runStep values from the new stage name into the old one to ensure compatibility. + For example, the 'Build' is not used in Jenkins but is used by other orchestrators, whereas 'Central Build' is + used by Jenkins but unused by other orchestrators. + */ +private static void handleRenamedStages(Script script) { + if(script.commonPipelineEnvironment.configuration.runStage.containsKey("Build")) { + script.commonPipelineEnvironment.configuration.runStage["Central Build"] = script.commonPipelineEnvironment.configuration.runStage["Build"] + } + + if(script.commonPipelineEnvironment.configuration.runStep.containsKey("Build")) { + script.commonPipelineEnvironment.configuration.runStep["Central Build"] = script.commonPipelineEnvironment.configuration.runStep["Build"] + } + + if(script.commonPipelineEnvironment.configuration.runStage.containsKey("Post")) { + script.commonPipelineEnvironment.configuration.runStage["Post Actions"] = script.commonPipelineEnvironment.configuration.runStage["Post"] + } + + if(script.commonPipelineEnvironment.configuration.runStep.containsKey("Post")) { + script.commonPipelineEnvironment.configuration.runStep["Post Actions"] = script.commonPipelineEnvironment.configuration.runStep["Post"] + } +}