@@ -264,17 +264,22 @@ func (j *Jenkins) DeleteJob(ctx context.Context, name string) (bool, error) {
264
264
return job .Delete (ctx )
265
265
}
266
266
267
+ // Get a job object
268
+ func (j * Jenkins ) GetJobObj (ctx context.Context , name string ) * Job {
269
+ return & Job {Jenkins : j , Raw : new (JobResponse ), Base : "/job/" + name }
270
+ }
271
+
267
272
// Invoke a job.
268
273
// First parameter job name, second parameter is optional Build parameters.
269
274
// Returns queue id
270
275
func (j * Jenkins ) BuildJob (ctx context.Context , name string , params map [string ]string ) (int64 , error ) {
271
- job := Job { Jenkins : j , Raw : new ( JobResponse ), Base : "/job/" + name }
276
+ job := j . GetJobObj ( ctx , name )
272
277
return job .InvokeSimple (ctx , params )
273
278
}
274
279
275
280
// A task in queue will be assigned a build number in a job after a few seconds.
276
281
// this function will return the build object.
277
- func (j * Jenkins ) GetBuildFromQueueID (ctx context.Context , queueid int64 ) (* Build , error ) {
282
+ func (j * Jenkins ) GetBuildFromQueueID (ctx context.Context , job * Job , queueid int64 ) (* Build , error ) {
278
283
task , err := j .GetQueueItem (ctx , queueid )
279
284
if err != nil {
280
285
return nil , err
@@ -288,12 +293,7 @@ func (j *Jenkins) GetBuildFromQueueID(ctx context.Context, queueid int64) (*Buil
288
293
}
289
294
}
290
295
291
- buildid := task .Raw .Executable .Number
292
- job , err := task .GetJob (ctx )
293
- if err != nil {
294
- return nil , err
295
- }
296
- build , err := job .GetBuild (ctx , buildid )
296
+ build , err := job .GetBuild (ctx , task .Raw .Executable .Number )
297
297
if err != nil {
298
298
return nil , err
299
299
}
0 commit comments