Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过queueId获取Build相关信息报404 #322

Open
joker-bai opened this issue Mar 21, 2024 · 1 comment
Open

通过queueId获取Build相关信息报404 #322

joker-bai opened this issue Mar 21, 2024 · 1 comment

Comments

@joker-bai
Copy link

通过如下方式执行Jenkins Build,无法拿到具体的Build信息.

func job_build(jenkins *gojenkins.Jenkins,ctx context.Context,jobname string) {
	jobarr := strings.Split(jobname, "/")
	newjobname := strings.Join(jobarr,"/job/")
	qid,err  := jenkins.BuildJob(ctx,newjobname,nil)
	if err != nil {panic(err)}
	build, err := jenkins.GetBuildFromQueueID(ctx, qid)
	if err != nil {panic(err)}
	for build.IsRunning(ctx) {
		time.Sleep(5000 * time.Millisecond)
		build.Poll(ctx)
	}
	fmt.Printf("build number %d with result: %v\n", build.GetBuildNumber(), 
    build.GetResult())

gojenkins的版本是v1.1.0
jenkins的版本是2.4.36

@ningblue
Copy link

GetBuildFromQueueID函数 已经获取了build内容,可以直接使用

func (j *Jenkins) GetBuildFromQueueID(ctx context.Context, job *Job, queueid int64) (*Build, error) {
	task, err := j.GetQueueItem(ctx, queueid)
	if err != nil {
		return nil, err
	}
	// Jenkins queue API has about 4.7second quiet period
	for task.Raw.Executable.Number == 0 {
		time.Sleep(1000 * time.Millisecond)
		_, err = task.Poll(ctx)
		if err != nil {
			return nil, err
		}
	}

	build, err := job.GetBuild(ctx, task.Raw.Executable.Number)
	if err != nil {
		return nil, err
	}
	return build, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants