fix(pipeline): update changedComponents handling to split string into list for conditional checks

Signed-off-by: zhenyus <zhenyus@mathmast.com>
This commit is contained in:
zhenyus 2025-02-22 20:33:26 +08:00
parent c8146e8f21
commit 1c663ed0f1
2 changed files with 18 additions and 21 deletions

View File

@ -24,7 +24,7 @@ def generateComponentStages(component, configurations) {
// 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.split(/\s+/).toList().contains(component.name)) {
def buildAgentImage = component.buildAgentImage def buildAgentImage = component.buildAgentImage
if (buildAgentImage == null || buildAgentImage.isEmpty()) { if (buildAgentImage == null || buildAgentImage.isEmpty()) {
log.warn("Pipeline", "Not set buildAgentImage for ${component.name}, using default build agent image") log.warn("Pipeline", "Not set buildAgentImage for ${component.name}, using default build agent image")
@ -82,7 +82,7 @@ spec:
node("dep-resolver-${component.name}") { node("dep-resolver-${component.name}") {
container('dep-resolver') { container('dep-resolver') {
script { 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" def buildAgentImage = env."${component.name}_buildAgentImage"
log.info("Pipeline", "Using ${buildAgentImage} as build agent image for dependencies resolving") log.info("Pipeline", "Using ${buildAgentImage} as build agent image for dependencies resolving")
def sourceFetcher = new SourceFetcher(this) def sourceFetcher = new SourceFetcher(this)
@ -114,7 +114,7 @@ spec:
// 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.split(/\s+/).toList().contains(component.name)) {
if (component.lintEnabled != null && component.lintEnabled) { if (component.lintEnabled != null && component.lintEnabled) {
log.info("Pipeline", "Code linting has enabled, preparing linter...") log.info("Pipeline", "Code linting has enabled, preparing linter...")
@ -176,7 +176,7 @@ spec:
node("code-linter-${component.name}") { node("code-linter-${component.name}") {
container('code-linter') { container('code-linter') {
script { 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) { if (component.lintEnabled != null && component.lintEnabled) {
log.info("Pipeline", "Code linting has enabled, linting code...") log.info("Pipeline", "Code linting has enabled, linting code...")
@ -218,7 +218,7 @@ spec:
// 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.split(/\s+/).toList().contains(component.name)) {
if (component.sastEnabled != null && component.sastEnabled) { if (component.sastEnabled != null && component.sastEnabled) {
log.info("Pipeline", "SAST scanning has enabled, preparing scanner...") log.info("Pipeline", "SAST scanning has enabled, preparing scanner...")
@ -243,7 +243,7 @@ spec:
{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.split(/\s+/).toList().contains(component.name)) && env.sastScannerContainerImage != null && !env.sastScannerContainerImage.isEmpty()
} }
} }
podTemplate( podTemplate(
@ -280,7 +280,7 @@ spec:
node("sast-scanner-${component.name}") { node("sast-scanner-${component.name}") {
container('sast-scanner') { container('sast-scanner') {
script { 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) { if (component.sastEnabled != null && component.sastEnabled) {
log.info("Pipeline", "SAST scanning has enabled, scanning code...") log.info("Pipeline", "SAST scanning has enabled, scanning code...")
@ -339,7 +339,7 @@ spec:
node("semantic-releasing-${component.name}") { node("semantic-releasing-${component.name}") {
container('semantic-releasing') { container('semantic-releasing') {
script { 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) { if (component.semanticReleaseEnabled != null && component.semanticReleaseEnabled) {
log.info("Pipeline", "Semantic releasing has enabled, releasing...") log.info("Pipeline", "Semantic releasing has enabled, releasing...")
@ -404,7 +404,7 @@ spec:
node("build-agent-${component.name}") { node("build-agent-${component.name}") {
container('build-agent') { container('build-agent') {
script { 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" def buildAgentImage = env."${component.name}_buildAgentImage"
log.info("Pipeline", "Using ${buildAgentImage} as build agent image for compilation & packaging") log.info("Pipeline", "Using ${buildAgentImage} as build agent image for compilation & packaging")
@ -463,7 +463,7 @@ spec:
// 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.split(/\s+/).toList().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}")
def imageBuilder def imageBuilder
if (component.imageBuilder == null || component.imageBuilder.isEmpty()) { if (component.imageBuilder == null || component.imageBuilder.isEmpty()) {
@ -521,7 +521,7 @@ spec:
node("image-builder-${component.name}") { node("image-builder-${component.name}") {
container('image-builder') { container('image-builder') {
script { 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) def sourceFetcher = new SourceFetcher(this)
sourceFetcher.fetch(configurations) sourceFetcher.fetch(configurations)
@ -606,7 +606,7 @@ spec:
node("argo-app-version-updater-${component.name}") { node("argo-app-version-updater-${component.name}") {
container("argo-app-version-updater") { container("argo-app-version-updater") {
script { 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) def argoApplicationVersionUpdater = new ArgoApplicationVersionUpdater(this, configurations)
argoApplicationVersionUpdater.update(configurations.environmentSlug, component) argoApplicationVersionUpdater.update(configurations.environmentSlug, component)
} }
@ -733,16 +733,13 @@ spec:
} }
stage("Pipeline :: Components Build (Dynamic Generated Stages)") { stage("Pipeline :: Components Build (Dynamic Generated Stages)") {
when {
expression {
return env.executeMode == "fully" || env.changedComponents.size() > 0
}
}
steps { steps {
script { script {
configurations.components.each { component -> if (env.executeMode == "fully" || env.changedComponents.split(/\s+/).toList().size() > 0) {
log.info("Pipeline", "Executing generated stages for ${component.name}...") configurations.components.each { component ->
generateComponentStages(component, configurations)() log.info("Pipeline", "Executing generated stages for ${component.name}...")
generateComponentStages(component, configurations)()
}
} }
} }
} }

View File

@ -7,7 +7,7 @@ executeFreeleapsPipeline {
serviceGitRepo = "https://freeleaps@dev.azure.com/freeleaps/freeleaps-service-hub/_git/freeleaps-service-hub" serviceGitRepo = "https://freeleaps@dev.azure.com/freeleaps/freeleaps-service-hub/_git/freeleaps-service-hub"
serviceGitRepoType = 'monorepo' serviceGitRepoType = 'monorepo'
serviceGitCredentialsId = 'freeleaps-azure-devops-credentials' serviceGitCredentialsId = 'freeleaps-azure-devops-credentials'
executeMode = 'fully' executeMode = 'on-demand'
commitMessageLintEnabled = false commitMessageLintEnabled = false
components = [ components = [
[ [