gojenkins icon indicating copy to clipboard operation
gojenkins copied to clipboard

fix: jenkins GetBuildFromQueueID return 404

Open iroben opened this issue 3 years ago • 3 comments

  1. credentials_test.go TestMain init global jenkins
  2. jenkins GetBuildFromQueueID return 404
  3. jenkins_test.go add GetBuildFromQueueID unit test function: TestJenkins_GetBuildFromQueueID
  4. README.md modify GetBuildFromQueueID example

iroben avatar Nov 24 '21 06:11 iroben

The current GetBuildFromQueueID method adds the job *Job parameter, which is incompatible with the V1.1.0 interface

iroben avatar Nov 24 '21 11:11 iroben

copy pasted the method in to my own code

asad-awadia avatar Jun 15 '22 15:06 asad-awadia

I have got an unexpected value of the jobURL: /job/DEV-IIS/job/data-api/, and the Base of Build like /job/DEV-IIS/job/data-api//52/ , 404 got~ so It may work to cut the final character

if strings.HasSuffix(jobURL, "/") {
	jobURL = jobURL[:len(jobURL)-1]
}
func (j *Job) GetBuild(ctx context.Context, id int64) (*Build, error) {

	// Support customized server URL,
	// i.e. Server : https://<domain>/jenkins/job/JOB1
	// "https://<domain>/jenkins/" is the server URL,
	// we are expecting jobURL = "job/JOB1"
	jobURL := strings.Replace(j.Raw.URL, j.Jenkins.Server, "", -1)
	if strings.HasSuffix(jobURL, "/") {
		jobURL = jobURL[:len(jobURL)-1]
	}
	build := Build{Jenkins: j.Jenkins, Job: j, Raw: new(BuildResponse), Depth: 1, Base: jobURL + "/" + strconv.FormatInt(id, 10)}
	status, err := build.Poll(ctx)
	if err != nil {
		return nil, err
	}
	if status == 200 {
		return &build, nil
	}
	return nil, errors.New(strconv.Itoa(status))
}

ns-cn avatar Dec 26 '22 08:12 ns-cn