Skip to content

CreateView Function doesn't allow creation of a view inside of a folder #318

@abrockmeyer-govtact

Description

@abrockmeyer-govtact

The endpoint is always on the main jenkins url.
I would hope to see an implementation where a folder name can be passed in as "test_folder" and the endpoint would be modified to be

if folder {
      endpoint := "jobs/" + folder + "/createView"
}

Or even just passing in "jobs/test_folder/jobs/test_folder2" could do nested folders 2 layers deep. Either would help.

func (j *Jenkins) CreateView(ctx context.Context, name string, viewType string) (*View, error) {
	view := &View{Jenkins: j, Raw: new(ViewResponse), Base: "/view/" + name}
	endpoint := "/createView"
	data := map[string]string{
		"name":   name,
		"mode":   viewType,
		"Submit": "OK",
		"json": makeJson(map[string]string{
			"name": name,
			"mode": viewType,
		}),
	}
	r, err := j.Requester.Post(ctx, endpoint, nil, view.Raw, data)

	if err != nil {
		return nil, err
	}

	if r.StatusCode == 200 {
		return j.GetView(ctx, name)
	}
	return nil, errors.New(strconv.Itoa(r.StatusCode))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions