Merge pull request #29 from msneeden/msneeden/build-url

Determine build url based on existence of job params
This commit is contained in:
Kohei YOSHIDA
2016-03-28 15:33:36 +09:00
3 changed files with 23 additions and 7 deletions
+13 -3
View File
@@ -206,10 +206,10 @@ func (jenkins *Jenkins) CreateView(listView ListView) error {
// Create a new build for this job.
// Params can be nil.
func (jenkins *Jenkins) Build(job Job, params url.Values) error {
if params == nil {
return jenkins.post(fmt.Sprintf("/job/%s/build", job.Name), params, nil)
} else {
if hasParams(job) {
return jenkins.post(fmt.Sprintf("/job/%s/buildWithParameters", job.Name), params, nil)
} else {
return jenkins.post(fmt.Sprintf("/job/%s/build", job.Name), params, nil)
}
}
@@ -294,3 +294,13 @@ func (jenkins *Jenkins) GetComputer(name string) (computer Computer, err error)
err = jenkins.get(fmt.Sprintf("/computer/%s", name), nil, &computer)
return
}
// hasParams returns a boolean value indicating if the job is parameterized
func hasParams(job Job) bool {
for _, action := range job.Actions {
if len(action.ParameterDefinitions) > 0 {
return true
}
}
return false
}
+4 -3
View File
@@ -36,9 +36,10 @@ type UpstreamCause struct {
}
type Job struct {
Name string `json:"name"`
Url string `json:"url"`
Color string `json:"color"`
Actions []Action `json:"actions"`
Name string `json:"name"`
Url string `json:"url"`
Color string `json:"color"`
Buildable bool `json:"buildable"`
DisplayName string `json:"displayName"`
+6 -1
View File
@@ -20,7 +20,8 @@ type Item struct {
}
type Action struct {
Causes []Cause `json:"causes"`
Causes []Cause `json:"causes"`
ParameterDefinitions []ParameterDefinition `json:"parameterDefinitions"`
}
type Cause struct {
@@ -30,6 +31,10 @@ type Cause struct {
UpstreamCause
}
type ParameterDefinition struct {
Name string `json:"name"`
}
type Task struct {
Name string `json:"name"`
Url string `json:"url"`