Skip to content

Commit

Permalink
Merge pull request bndr#194 from signalfx/SFEnhancements
Browse files Browse the repository at this point in the history
Improvements and bug fixes
  • Loading branch information
bndr authored Apr 1, 2020
2 parents a7b1b21 + 900cf3f commit 65ee8c9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 22 deletions.
16 changes: 8 additions & 8 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ type ViewData struct {
URL string `json:"url"`
}
type ExecutorResponse struct {
AssignedLabels []struct{} `json:"assignedLabels"`
Description interface{} `json:"description"`
Jobs []InnerJob `json:"jobs"`
Mode string `json:"mode"`
NodeDescription string `json:"nodeDescription"`
NodeName string `json:"nodeName"`
NumExecutors int64 `json:"numExecutors"`
OverallLoad struct{} `json:"overallLoad"`
AssignedLabels []map[string]string `json:"assignedLabels"`
Description interface{} `json:"description"`
Jobs []InnerJob `json:"jobs"`
Mode string `json:"mode"`
NodeDescription string `json:"nodeDescription"`
NodeName string `json:"nodeName"`
NumExecutors int64 `json:"numExecutors"`
OverallLoad struct{} `json:"overallLoad"`
PrimaryView struct {
Name string `json:"name"`
URL string `json:"url"`
Expand Down
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/bndr/gojenkins

go 1.13

require (
github.com/stretchr/testify v1.4.0
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa
)
7 changes: 5 additions & 2 deletions jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ func (j *Jenkins) initLoggers() {

// Get Basic Information About Jenkins
func (j *Jenkins) Info() (*ExecutorResponse, error) {
_, err := j.Requester.Get("/", j.Raw, nil)

rsp, err := j.Requester.GetJSON("/", j.Raw, nil)
if err != nil {
return nil, err
}

// The cached version which is set in Init(), might get staled, update
j.Version = rsp.Header.Get("X-Jenkins")

return j.Raw, nil
}

Expand Down
40 changes: 28 additions & 12 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ type JobResponse struct {
IconUrl string `json:"iconUrl"`
Score int64 `json:"score"`
} `json:"healthReport"`
InQueue bool `json:"inQueue"`
KeepDependencies bool `json:"keepDependencies"`
LastBuild JobBuild `json:"lastBuild"`
LastCompletedBuild JobBuild `json:"lastCompletedBuild"`
LastFailedBuild JobBuild `json:"lastFailedBuild"`
LastStableBuild JobBuild `json:"lastStableBuild"`
LastSuccessfulBuild JobBuild `json:"lastSuccessfulBuild"`
LastUnstableBuild JobBuild `json:"lastUnstableBuild"`
LastUnsuccessfulBuild JobBuild `json:"lastUnsuccessfulBuild"`
Name string `json:"name"`
NextBuildNumber int64 `json:"nextBuildNumber"`
InQueue bool `json:"inQueue"`
KeepDependencies bool `json:"keepDependencies"`
LastBuild JobBuild `json:"lastBuild"`
LastCompletedBuild JobBuild `json:"lastCompletedBuild"`
LastFailedBuild JobBuild `json:"lastFailedBuild"`
LastStableBuild JobBuild `json:"lastStableBuild"`
LastSuccessfulBuild JobBuild `json:"lastSuccessfulBuild"`
LastUnstableBuild JobBuild `json:"lastUnstableBuild"`
LastUnsuccessfulBuild JobBuild `json:"lastUnsuccessfulBuild"`
Name string `json:"name"`
NextBuildNumber int64 `json:"nextBuildNumber"`
Property []struct {
ParameterDefinitions []ParameterDefinition `json:"parameterDefinitions"`
} `json:"property"`
Expand Down Expand Up @@ -121,7 +121,11 @@ func (j *Job) GetDetails() *JobResponse {

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

func (j *Job) GetBuildsFields(fields []string, custom interface{}) error {
if fields == nil || len(fields) == 0 {
return fmt.Errorf("one or more field value needs to be specified")
}
// limit overhead using builds instead of allBuilds, which returns the last 100 build
_, err := j.Jenkins.Requester.GetJSON(j.Base, &custom, map[string]string{"tree": "builds[" + strings.Join(fields, ",") + "]"})
if err != nil {
return err
}
return nil
}

// Returns All Builds with Number and URL
func (j *Job) GetAllBuildIds() ([]JobBuild, error) {
var buildsResp struct {
Expand Down
1 change: 1 addition & 0 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Node struct {
}

type NodeResponse struct {
Class string `json:"_class"`
Actions []interface{} `json:"actions"`
DisplayName string `json:"displayName"`
Executors []struct {
Expand Down

0 comments on commit 65ee8c9

Please sign in to comment.