@@ -73,17 +73,17 @@ type JobResponse struct {
73
73
IconUrl string `json:"iconUrl"`
74
74
Score int64 `json:"score"`
75
75
} `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"`
87
87
Property []struct {
88
88
ParameterDefinitions []ParameterDefinition `json:"parameterDefinitions"`
89
89
} `json:"property"`
@@ -121,7 +121,11 @@ func (j *Job) GetDetails() *JobResponse {
121
121
122
122
func (j * Job ) GetBuild (id int64 ) (* Build , error ) {
123
123
// 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
125
129
build := Build {Jenkins : j .Jenkins , Job : j , Raw : new (BuildResponse ), Depth : 1 , Base : jobURL + "/" + strconv .FormatInt (id , 10 )}
126
130
status , err := build .Poll ()
127
131
if err != nil {
@@ -188,6 +192,18 @@ func (j *Job) GetLastCompletedBuild() (*Build, error) {
188
192
return j .getBuildByType ("lastCompletedBuild" )
189
193
}
190
194
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
+
191
207
// Returns All Builds with Number and URL
192
208
func (j * Job ) GetAllBuildIds () ([]JobBuild , error ) {
193
209
var buildsResp struct {
0 commit comments