From 36cece507b97d56b01d87f2195803b1067c7c8fc Mon Sep 17 00:00:00 2001 From: KubeSphere CI Bot <47586280+ks-ci-bot@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:18:39 +0800 Subject: [PATCH] set pruneDeadBranches to false when without discarder (#1020) Co-authored-by: jackyu --- 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 {