gojenkins
gojenkins copied to clipboard
fix: jenkins GetBuildFromQueueID return 404
- credentials_test.go TestMain init global jenkins
- jenkins
GetBuildFromQueueID
return 404 - jenkins_test.go add
GetBuildFromQueueID
unit test function:TestJenkins_GetBuildFromQueueID
- README.md modify
GetBuildFromQueueID
example
The current GetBuildFromQueueID
method adds the job *Job
parameter, which is incompatible with the V1.1.0 interface
copy pasted the method in to my own code
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))
}