From 1c663ed0f1927894fac451c2b8c8cc5e86c2fb84 Mon Sep 17 00:00:00 2001 From: zhenyus Date: Sat, 22 Feb 2025 20:33:26 +0800 Subject: [PATCH] fix(pipeline): update changedComponents handling to split string into list for conditional checks Signed-off-by: zhenyus --- .../vars/executeFreeleapsPipeline.groovy | 37 +++++++++---------- .../ci/freeleaps-service-hub/Jenkinsfile | 2 +- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/first-class-pipeline/vars/executeFreeleapsPipeline.groovy b/first-class-pipeline/vars/executeFreeleapsPipeline.groovy index be81f3bf..75cd7ce8 100644 --- a/first-class-pipeline/vars/executeFreeleapsPipeline.groovy +++ b/first-class-pipeline/vars/executeFreeleapsPipeline.groovy @@ -24,7 +24,7 @@ def generateComponentStages(component, configurations) { // Build Agent Setup {stage("${component.name} :: Build Agent Setup") { script { - if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { + if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().contains(component.name)) { def buildAgentImage = component.buildAgentImage if (buildAgentImage == null || buildAgentImage.isEmpty()) { log.warn("Pipeline", "Not set buildAgentImage for ${component.name}, using default build agent image") @@ -82,7 +82,7 @@ spec: node("dep-resolver-${component.name}") { container('dep-resolver') { script { - if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { + if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().contains(component.name)) { def buildAgentImage = env."${component.name}_buildAgentImage" log.info("Pipeline", "Using ${buildAgentImage} as build agent image for dependencies resolving") def sourceFetcher = new SourceFetcher(this) @@ -114,7 +114,7 @@ spec: // Code Linter Environment Preparation {stage("${component.name} :: Code Linter Preparation") { script { - if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { + if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().contains(component.name)) { if (component.lintEnabled != null && component.lintEnabled) { log.info("Pipeline", "Code linting has enabled, preparing linter...") @@ -176,7 +176,7 @@ spec: node("code-linter-${component.name}") { container('code-linter') { script { - if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { + if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().contains(component.name)) { if (component.lintEnabled != null && component.lintEnabled) { log.info("Pipeline", "Code linting has enabled, linting code...") @@ -218,7 +218,7 @@ spec: // SAST Scanner Environment Preparation {stage("${component.name} :: SAST Scanner Preparation") { script { - if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { + if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().contains(component.name)) { if (component.sastEnabled != null && component.sastEnabled) { log.info("Pipeline", "SAST scanning has enabled, preparing scanner...") @@ -243,7 +243,7 @@ spec: {stage("${component.name} :: SAST Scanning") { when { expression { - return (env.executeMode == "fully" || env.changedComponents.contains(component.name)) && env.sastScannerContainerImage != null && !env.sastScannerContainerImage.isEmpty() + return (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().contains(component.name)) && env.sastScannerContainerImage != null && !env.sastScannerContainerImage.isEmpty() } } podTemplate( @@ -280,7 +280,7 @@ spec: node("sast-scanner-${component.name}") { container('sast-scanner') { script { - if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { + if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().contains(component.name)) { if (component.sastEnabled != null && component.sastEnabled) { log.info("Pipeline", "SAST scanning has enabled, scanning code...") @@ -339,7 +339,7 @@ spec: node("semantic-releasing-${component.name}") { container('semantic-releasing') { script { - if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { + if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().contains(component.name)) { if (component.semanticReleaseEnabled != null && component.semanticReleaseEnabled) { log.info("Pipeline", "Semantic releasing has enabled, releasing...") @@ -404,7 +404,7 @@ spec: node("build-agent-${component.name}") { container('build-agent') { script { - if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { + if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().contains(component.name)) { def buildAgentImage = env."${component.name}_buildAgentImage" log.info("Pipeline", "Using ${buildAgentImage} as build agent image for compilation & packaging") @@ -463,7 +463,7 @@ spec: // Image Builder Setup {stage("${component.name} :: Image Builder Setup") { script { - if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { + if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().contains(component.name)) { log.info("Pipeline", "Ready to setup image builder for ${component.name}") def imageBuilder if (component.imageBuilder == null || component.imageBuilder.isEmpty()) { @@ -521,7 +521,7 @@ spec: node("image-builder-${component.name}") { container('image-builder') { script { - if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { + if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().contains(component.name)) { def sourceFetcher = new SourceFetcher(this) sourceFetcher.fetch(configurations) @@ -606,7 +606,7 @@ spec: node("argo-app-version-updater-${component.name}") { container("argo-app-version-updater") { script { - if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { + if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().contains(component.name)) { def argoApplicationVersionUpdater = new ArgoApplicationVersionUpdater(this, configurations) argoApplicationVersionUpdater.update(configurations.environmentSlug, component) } @@ -733,16 +733,13 @@ spec: } stage("Pipeline :: Components Build (Dynamic Generated Stages)") { - when { - expression { - return env.executeMode == "fully" || env.changedComponents.size() > 0 - } - } steps { script { - configurations.components.each { component -> - log.info("Pipeline", "Executing generated stages for ${component.name}...") - generateComponentStages(component, configurations)() + if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().size() > 0) { + configurations.components.each { component -> + log.info("Pipeline", "Executing generated stages for ${component.name}...") + generateComponentStages(component, configurations)() + } } } } diff --git a/freeleaps/alpha/ci/freeleaps-service-hub/Jenkinsfile b/freeleaps/alpha/ci/freeleaps-service-hub/Jenkinsfile index c5272844..19018ff7 100644 --- a/freeleaps/alpha/ci/freeleaps-service-hub/Jenkinsfile +++ b/freeleaps/alpha/ci/freeleaps-service-hub/Jenkinsfile @@ -7,7 +7,7 @@ executeFreeleapsPipeline { serviceGitRepo = "https://freeleaps@dev.azure.com/freeleaps/freeleaps-service-hub/_git/freeleaps-service-hub" serviceGitRepoType = 'monorepo' serviceGitCredentialsId = 'freeleaps-azure-devops-credentials' - executeMode = 'fully' + executeMode = 'on-demand' commitMessageLintEnabled = false components = [ [