Skip to content

Commit 65ee8c9

Browse files
authored
Merge pull request #194 from signalfx/SFEnhancements
Improvements and bug fixes
2 parents a7b1b21 + 900cf3f commit 65ee8c9

File tree

5 files changed

+50
-22
lines changed

5 files changed

+50
-22
lines changed

executor.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ type ViewData struct {
2323
URL string `json:"url"`
2424
}
2525
type ExecutorResponse struct {
26-
AssignedLabels []struct{} `json:"assignedLabels"`
27-
Description interface{} `json:"description"`
28-
Jobs []InnerJob `json:"jobs"`
29-
Mode string `json:"mode"`
30-
NodeDescription string `json:"nodeDescription"`
31-
NodeName string `json:"nodeName"`
32-
NumExecutors int64 `json:"numExecutors"`
33-
OverallLoad struct{} `json:"overallLoad"`
26+
AssignedLabels []map[string]string `json:"assignedLabels"`
27+
Description interface{} `json:"description"`
28+
Jobs []InnerJob `json:"jobs"`
29+
Mode string `json:"mode"`
30+
NodeDescription string `json:"nodeDescription"`
31+
NodeName string `json:"nodeName"`
32+
NumExecutors int64 `json:"numExecutors"`
33+
OverallLoad struct{} `json:"overallLoad"`
3434
PrimaryView struct {
3535
Name string `json:"name"`
3636
URL string `json:"url"`

go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/bndr/gojenkins
2+
3+
go 1.13
4+
5+
require (
6+
github.com/stretchr/testify v1.4.0
7+
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa
8+
)

jenkins.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ func (j *Jenkins) initLoggers() {
8282

8383
// Get Basic Information About Jenkins
8484
func (j *Jenkins) Info() (*ExecutorResponse, error) {
85-
_, err := j.Requester.Get("/", j.Raw, nil)
86-
85+
rsp, err := j.Requester.GetJSON("/", j.Raw, nil)
8786
if err != nil {
8887
return nil, err
8988
}
89+
90+
// The cached version which is set in Init(), might get staled, update
91+
j.Version = rsp.Header.Get("X-Jenkins")
92+
9093
return j.Raw, nil
9194
}
9295

job.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ type JobResponse struct {
7373
IconUrl string `json:"iconUrl"`
7474
Score int64 `json:"score"`
7575
} `json:"healthReport"`
76-
InQueue bool `json:"inQueue"`
77-
KeepDependencies bool `json:"keepDependencies"`
78-
LastBuild JobBuild `json:"lastBuild"`
79-
LastCompletedBuild JobBuild `json:"lastCompletedBuild"`
80-
LastFailedBuild JobBuild `json:"lastFailedBuild"`
81-
LastStableBuild JobBuild `json:"lastStableBuild"`
82-
LastSuccessfulBuild JobBuild `json:"lastSuccessfulBuild"`
83-
LastUnstableBuild JobBuild `json:"lastUnstableBuild"`
84-
LastUnsuccessfulBuild JobBuild `json:"lastUnsuccessfulBuild"`
85-
Name string `json:"name"`
86-
NextBuildNumber int64 `json:"nextBuildNumber"`
76+
InQueue bool `json:"inQueue"`
77+
KeepDependencies bool `json:"keepDependencies"`
78+
LastBuild JobBuild `json:"lastBuild"`
79+
LastCompletedBuild JobBuild `json:"lastCompletedBuild"`
80+
LastFailedBuild JobBuild `json:"lastFailedBuild"`
81+
LastStableBuild JobBuild `json:"lastStableBuild"`
82+
LastSuccessfulBuild JobBuild `json:"lastSuccessfulBuild"`
83+
LastUnstableBuild JobBuild `json:"lastUnstableBuild"`
84+
LastUnsuccessfulBuild JobBuild `json:"lastUnsuccessfulBuild"`
85+
Name string `json:"name"`
86+
NextBuildNumber int64 `json:"nextBuildNumber"`
8787
Property []struct {
8888
ParameterDefinitions []ParameterDefinition `json:"parameterDefinitions"`
8989
} `json:"property"`
@@ -121,7 +121,11 @@ func (j *Job) GetDetails() *JobResponse {
121121

122122
func (j *Job) GetBuild(id int64) (*Build, error) {
123123
// use job embedded URL to properly handle jobs in folders
124-
jobURL := strings.Replace(j.Raw.URL, j.Jenkins.Server, "", -1)
124+
url, err := url.Parse(j.Raw.URL)
125+
if err != nil {
126+
return nil, err
127+
}
128+
jobURL := url.Path
125129
build := Build{Jenkins: j.Jenkins, Job: j, Raw: new(BuildResponse), Depth: 1, Base: jobURL + "/" + strconv.FormatInt(id, 10)}
126130
status, err := build.Poll()
127131
if err != nil {
@@ -188,6 +192,18 @@ func (j *Job) GetLastCompletedBuild() (*Build, error) {
188192
return j.getBuildByType("lastCompletedBuild")
189193
}
190194

195+
func (j *Job) GetBuildsFields(fields []string, custom interface{}) error {
196+
if fields == nil || len(fields) == 0 {
197+
return fmt.Errorf("one or more field value needs to be specified")
198+
}
199+
// limit overhead using builds instead of allBuilds, which returns the last 100 build
200+
_, err := j.Jenkins.Requester.GetJSON(j.Base, &custom, map[string]string{"tree": "builds[" + strings.Join(fields, ",") + "]"})
201+
if err != nil {
202+
return err
203+
}
204+
return nil
205+
}
206+
191207
// Returns All Builds with Number and URL
192208
func (j *Job) GetAllBuildIds() ([]JobBuild, error) {
193209
var buildsResp struct {

node.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Node struct {
3232
}
3333

3434
type NodeResponse struct {
35+
Class string `json:"_class"`
3536
Actions []interface{} `json:"actions"`
3637
DisplayName string `json:"displayName"`
3738
Executors []struct {

0 commit comments

Comments
 (0)