From cc86147af3263d6cb10ba4661b6faacec5b0ae8f Mon Sep 17 00:00:00 2001 From: jackyu Date: Mon, 6 Nov 2023 00:28:08 +0800 Subject: [PATCH] set pruneDeadBranches to false when without discarder --- pkg/client/devops/jenkins/pipeline_internal.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/client/devops/jenkins/pipeline_internal.go b/pkg/client/devops/jenkins/pipeline_internal.go index 484d0601..a3162240 100644 --- a/pkg/client/devops/jenkins/pipeline_internal.go +++ b/pkg/client/devops/jenkins/pipeline_internal.go @@ -434,13 +434,15 @@ func createMultiBranchPipelineConfigXml(projectName string, pipeline *devopsv1al appendMultiBranchJobTriggerToEtree(properties, pipeline.MultiBranchJobTrigger) } + discarder := project.CreateElement("orphanedItemStrategy") + discarder.CreateAttr("class", "com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy") + discarder.CreateAttr("plugin", "cloudbees-folder") if pipeline.Discarder != nil { - discarder := project.CreateElement("orphanedItemStrategy") - discarder.CreateAttr("class", "com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy") - discarder.CreateAttr("plugin", "cloudbees-folder") discarder.CreateElement("pruneDeadBranches").SetText("true") discarder.CreateElement("daysToKeep").SetText(pipeline.Discarder.DaysToKeep) discarder.CreateElement("numToKeep").SetText(pipeline.Discarder.NumToKeep) + } else { + discarder.CreateElement("pruneDeadBranches").SetText("false") } triggers := project.CreateElement("triggers") @@ -525,9 +527,11 @@ func parseMultiBranchPipelineConfigXml(config string) (*devopsv1alpha3.MultiBran } if discarder := project.SelectElement("orphanedItemStrategy"); discarder != nil { - pipeline.Discarder = &devopsv1alpha3.DiscarderProperty{ - DaysToKeep: getElementTextValueOrEmpty(discarder, "daysToKeep"), - NumToKeep: getElementTextValueOrEmpty(discarder, "numToKeep"), + if getElementTextValueOrEmpty(discarder, "pruneDeadBranches") == "true" { + pipeline.Discarder = &devopsv1alpha3.DiscarderProperty{ + DaysToKeep: getElementTextValueOrEmpty(discarder, "daysToKeep"), + NumToKeep: getElementTextValueOrEmpty(discarder, "numToKeep"), + } } } if triggers := project.SelectElement("triggers"); triggers != nil {