fix(pipeline): correct stage closure syntax in component stage generation

Signed-off-by: 孙振宇 <>
This commit is contained in:
孙振宇 2025-02-10 07:03:47 +08:00
parent b906867e36
commit ef9c74a43e

View File

@ -18,7 +18,7 @@ def generateComponentStages(component, configurations) {
def stages = [] def stages = []
stages.addAll([ stages.addAll([
// Build Agent Setup // Build Agent Setup
stage("${component.name} :: Build Agent Setup") { {stage("${component.name} :: Build Agent Setup") {
script { script {
if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) {
def buildAgentImage = component.buildAgentImage def buildAgentImage = component.buildAgentImage
@ -41,9 +41,9 @@ def generateComponentStages(component, configurations) {
env.buildAgentImage = buildAgentImage env.buildAgentImage = buildAgentImage
} }
} }
}, }},
// Dependencies Resolving // Dependencies Resolving
stage("${component.name} :: Dependencies Resolving") { {stage("${component.name} :: Dependencies Resolving") {
podTemplate( podTemplate(
label: "dep-resolver-${component.name}", label: "dep-resolver-${component.name}",
containers: [ containers: [
@ -82,13 +82,13 @@ def generateComponentStages(component, configurations) {
} }
} }
} }
}, }},
]) ])
if (component.lintEnabled != null && component.lintEnabled) { if (component.lintEnabled != null && component.lintEnabled) {
stages.addAll([ stages.addAll([
// Code Linter Environment Preparation // Code Linter Environment Preparation
stage("${component.name} :: Code Linter Preparation") { {stage("${component.name} :: Code Linter Preparation") {
script { script {
if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) {
if (component.lintEnabled != null && component.lintEnabled) { if (component.lintEnabled != null && component.lintEnabled) {
@ -115,9 +115,9 @@ def generateComponentStages(component, configurations) {
} }
} }
} }
}, }},
// Code Linting // Code Linting
stage("${component.name} :: Code Linting") { {stage("${component.name} :: Code Linting") {
podTemplate( podTemplate(
label: "code-linter-${component.name}", label: "code-linter-${component.name}",
containers: [ containers: [
@ -166,14 +166,14 @@ def generateComponentStages(component, configurations) {
} }
} }
} }
} }}
]) ])
} }
if (component.sastEnabled != null && component.sastEnabled) { if (component.sastEnabled != null && component.sastEnabled) {
stages.addAll([ stages.addAll([
// SAST Scanner Environment Preparation // SAST Scanner Environment Preparation
stage("${component.name} :: SAST Scanner Preparation") { {stage("${component.name} :: SAST Scanner Preparation") {
script { script {
if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) {
if (component.sastEnabled != null && component.sastEnabled) { if (component.sastEnabled != null && component.sastEnabled) {
@ -195,9 +195,9 @@ def generateComponentStages(component, configurations) {
} }
} }
} }
}, }},
// SAST Scanning // SAST Scanning
stage("${component.name} :: SAST Scanning") { {stage("${component.name} :: SAST Scanning") {
when { when {
expression { expression {
return (env.executeMode == "fully" || env.changedComponents.contains(component.name)) && env.sastScannerContainerImage != null && !env.sastScannerContainerImage.isEmpty() return (env.executeMode == "fully" || env.changedComponents.contains(component.name)) && env.sastScannerContainerImage != null && !env.sastScannerContainerImage.isEmpty()
@ -235,14 +235,14 @@ def generateComponentStages(component, configurations) {
} }
} }
} }
} }}
]) ])
} }
if (component.semanticReleaseEnabled != null && component.semanticReleaseEnabled) { if (component.semanticReleaseEnabled != null && component.semanticReleaseEnabled) {
stages.addAll([ stages.addAll([
// Semantic Releasing // Semantic Releasing
stage("${component.name} :: Semantic Releasing") { {stage("${component.name} :: Semantic Releasing") {
podTemplate( podTemplate(
label: "semantic-releasing-${component.name}", label: "semantic-releasing-${component.name}",
containers: [ containers: [
@ -273,13 +273,13 @@ def generateComponentStages(component, configurations) {
} }
} }
} }
} }}
]) ])
} }
stages.addAll([ stages.addAll([
// Compilation & Packaging // Compilation & Packaging
stage("${component.name} :: Compilation & Packaging") { {stage("${component.name} :: Compilation & Packaging") {
podTemplate( podTemplate(
label: "build-agent-${component.name}", label: "build-agent-${component.name}",
containers: [ containers: [
@ -349,9 +349,9 @@ def generateComponentStages(component, configurations) {
} }
} }
} }
}, }},
// Image Builder Setup // Image Builder Setup
stage("${component.name} :: Image Builder Setup") { {stage("${component.name} :: Image Builder Setup") {
script { script {
if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) { if (env.executeMode == "fully" || env.changedComponents.contains(component.name)) {
log.info("Pipeline", "Ready to setup image builder for ${component.name}") log.info("Pipeline", "Ready to setup image builder for ${component.name}")
@ -370,9 +370,9 @@ def generateComponentStages(component, configurations) {
log.info("Pipeline", "Using ${imageBuilder.builder} (image: ${imageBuilder.image}) as image builder for ${component.name}") log.info("Pipeline", "Using ${imageBuilder.builder} (image: ${imageBuilder.image}) as image builder for ${component.name}")
} }
} }
}, }},
// Image Building & Publishing // Image Building & Publishing
stage("${component.name} :: Image Building & Publishing") { {stage("${component.name} :: Image Building & Publishing") {
podTemplate( podTemplate(
label: "image-builder-${component.name}", label: "image-builder-${component.name}",
containers: [ containers: [
@ -441,11 +441,11 @@ def generateComponentStages(component, configurations) {
} }
} }
} }
} }}
]) ])
return { return {
stages.each { stage -> stages.each { stageClosure ->
stage.call() stageClosure()
} }
} }
} }
@ -555,7 +555,7 @@ spec:
steps { steps {
script { script {
def componentStages = configurations.components.collectEntries { component -> def componentStages = configurations.components.collectEntries { component ->
["Generated Stage :: ${component}": generateComponentStages(component, configurations)] ["Generated Stage :: ${component.name}": generateComponentStages(component, configurations)]
} }
parallel componentStages parallel componentStages
} }