diff --git a/pkg/models/devops/project_pipeline.go b/pkg/models/devops/project_pipeline.go
index bccd1625b..cf7e1eccf 100644
--- a/pkg/models/devops/project_pipeline.go
+++ b/pkg/models/devops/project_pipeline.go
@@ -15,14 +15,15 @@ package devops
import (
"fmt"
+ "strconv"
+ "strings"
+ "time"
+
"github.com/beevik/etree"
"github.com/kubesphere/sonargo/sonar"
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/gojenkins"
"kubesphere.io/kubesphere/pkg/simple/client"
- "strconv"
- "strings"
- "time"
)
const (
@@ -375,16 +376,47 @@ func (s *Parameters) fromEtree(properties *etree.Element) *Parameters {
*s = append(*s, &Parameter{
Name: param.SelectElement("name").Text(),
Description: param.SelectElement("description").Text(),
- DefaultValue: param.SelectElement("name").Text(),
+ DefaultValue: param.SelectElement("defaultValue").Text(),
Type: ParameterTypeMap["hudson.model.PasswordParameterDefinition"],
})
case "hudson.model.ChoiceParameterDefinition":
+ /* case1
+
+ 1
+ x
+
+
+ 1
+ 2
+ 3
+
+
+
+ */
+ /* case2
+
+ 1
+ x
+
+ 1
+ 2
+ 3
+
+
+ */
choiceParameter := &Parameter{
Name: param.SelectElement("name").Text(),
Description: param.SelectElement("description").Text(),
Type: ParameterTypeMap["hudson.model.ChoiceParameterDefinition"],
}
- choices := param.SelectElement("choices").SelectElement("a").SelectElements("string")
+ choicesSection := param.SelectElement("choices")
+ a := choicesSection.SelectElement("a")
+ var choices []*etree.Element
+ if a != nil {
+ choices = a.SelectElements("string")
+ } else {
+ choices = choicesSection.SelectElements("string")
+ }
for _, choice := range choices {
choiceParameter.DefaultValue += fmt.Sprintf("%s\n", choice.Text())
}
diff --git a/pkg/models/devops/project_pipeline_test.go b/pkg/models/devops/project_pipeline_test.go
index 4f572b554..f1473abdf 100644
--- a/pkg/models/devops/project_pipeline_test.go
+++ b/pkg/models/devops/project_pipeline_test.go
@@ -631,3 +631,171 @@ func Test_MultiBranchPipelineMultibranchTrigger(t *testing.T) {
}
}
+
+func Test_ParsePipelineConfigChoiceParameters(t *testing.T) {
+
+ case1 := `
+
+
+
+
+
+
+BIOGRAPHY
+PERSON
+PASSWORD
+TOGGLE
+
+
+
+
+
+false
+
+
+
+
+7
+10
+-1
+-1
+
+
+
+
+
+PERSON
+Who should I say hello to?
+Mr Jenkins
+false
+
+
+BIOGRAPHY
+Enter some information about the person
+
+false
+
+
+TOGGLE
+Toggle this value
+true
+
+
+PASSWORD
+Enter a password
+
+{AQAAABAAAAAQHD/HoXKklrRKtlQ5ylr1lgN1dj7im57I8SGfkLIe17s=}
+
+
+
+1
+x
+
+
+1
+2
+3
+
+
+
+
+
+
+
+
+true
+
+
+false
+`
+ case2 := `
+
+
+
+
+
+
+
+BIOGRAPHY
+PERSON
+PASSWORD
+TOGGLE
+
+
+
+
+
+false
+
+
+
+
+7
+10
+-1
+-1
+
+
+
+
+
+PERSON
+Who should I say hello to?
+Mr Jenkins
+false
+
+
+BIOGRAPHY
+Enter some information about the person
+
+false
+
+
+TOGGLE
+Toggle this value
+true
+
+
+PASSWORD
+Enter a password
+
+{AQAAABAAAAAQHD/HoXKklrRKtlQ5ylr1lgN1dj7im57I8SGfkLIe17s=}
+
+
+
+1
+x
+
+1
+2
+3
+
+
+
+
+
+
+
+true
+
+
+false
+`
+
+ case1Pipeline, err := parsePipelineConfigXml(case1)
+ if err != nil {
+ t.Fatal(err)
+ }
+ case2Pipeline, err := parsePipelineConfigXml(case2)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !reflect.DeepEqual(case1Pipeline, case2Pipeline) {
+ t.Fatalf("case1 [%+v] case2 [%+v] should equal ", case1Pipeline, case2Pipeline)
+ }
+
+}