Skip to content

Commit

Permalink
the jobUrl end with /
Browse files Browse the repository at this point in the history
  • Loading branch information
ns-cn committed Dec 26, 2022
1 parent 45fe314 commit eec235a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ func (j *Job) GetBuild(ctx context.Context, id int64) (*Build, error) {
// "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 {
Expand Down

1 comment on commit eec235a

@ns-cn
Copy link
Author

@ns-cn ns-cn commented on eec235a Dec 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have got a 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))
}

Please sign in to comment.