Skip to content

Commit

Permalink
fix: handle legacy stage name differences (#4733)
Browse files Browse the repository at this point in the history
* add name difference handler function

* add conditions for setting keys

---------

Co-authored-by: Gulom Alimov <[email protected]>
Co-authored-by: Christopher Fenner <[email protected]>
  • Loading branch information
3 people authored Jan 10, 2024
1 parent 89e1e01 commit 2b2c441
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion vars/piperInitRunStageConfiguration.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"]
}
}

0 comments on commit 2b2c441

Please sign in to comment.