This repository has been archived by the owner on Mar 4, 2021. It is now read-only.
forked from yosida95/golang-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob.go
64 lines (52 loc) · 1.72 KB
/
job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package gojenkins
import (
"fmt"
"net/url"
)
type Build struct {
Id string `json:"id"`
Number int `json:"number"`
Url string `json:"url"`
FullDisplayName string `json:"fullDisplayName"`
Description string `json:"description"`
Timestamp int `json:"timestamp"`
Duration int `json:"duration"`
EstimatedDuration int `json:"estimatedDuration"`
Building bool `json:"building"`
KeepLog bool `json:"keepLog"`
Result string `json:"result"`
}
type Job struct {
Name string `json:"name"`
Url string `json:"url"`
Color string `json:"color"`
Buildable bool `json:"buildable"`
DisplayName string `json:"displayName"`
Description string `json:"description"`
LastCompletedBuild Build `json:"lastCompletedBuild"`
LastFailedBuild Build `json:"lastFailedBuild"`
LastStableBuild Build `json:"lastStableBuild"`
LastSuccessfulBuild Build `json:"lastSuccessfulBuild"`
LastUnstableBuild Build `json:"lastUnstableBuild"`
LastUnsuccessfulBuild Build `json:"lastUnsuccessfulBuild"`
}
func (jenkins *Jenkins) GetJobs() (jobs []Job, err error) {
var payload = struct {
Jobs []Job `json:"jobs"`
}{
Jobs: jobs,
}
err = jenkins.get("", nil, &payload, DefaultOptions)
return
}
func (jenkins *Jenkins) GetJob(name string) (job Job, err error) {
err = jenkins.get(fmt.Sprintf("/job/%s", name), nil, &job, DefaultOptions)
return
}
func (jenkins *Jenkins) GetBuild(job Job, number int) (build Build, err error) {
err = jenkins.get(fmt.Sprintf("/job/%s/%d", job.Name, number), nil, &build, DefaultOptions)
return
}
func (jenkins *Jenkins) Build(job Job, params url.Values) error {
return jenkins.post(fmt.Sprintf("/job/%s/buildWithParameters", job.Name), params, nil, DefaultOptions)
}