Skip to content

Commit

Permalink
set pruneDeadBranches to false when without discarder (#1021)
Browse files Browse the repository at this point in the history
Co-authored-by: jackyu <jackyu@yunify.com>
  • Loading branch information
ks-ci-bot and yudong2015 authored Nov 6, 2023
1 parent 67d7eaf commit 370675c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/client/devops/jenkins/pipeline_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 370675c

Please sign in to comment.