jenkins_api_client icon indicating copy to clipboard operation
jenkins_api_client copied to clipboard

Creating Nested Views

Open coofercat opened this issue 10 years ago • 1 comments

Is there a way to create Nested Views with jenkins_api_client?

I'd like to create a Nested View called 'Pipelines'. I'd then like to create Build Pipeline View sub-views within it. Looking at the code, it seems like views have to be of type 'listview' or 'myview', otherwise the code dismisses the request without actually asking Jenkins.

I had a bit of a hack about with the code, and came up with this, although it feels like I've taken a possibly important check out of it (although Jenkins will return errors if you try to create an invalid view type):

def create(view_name, type = "listview", mode = 'hudson.model.ListView')
  @logger.info "Creating a view '#{view_name}' of type '#{type}'"
   initial_post_params = {
     "name" => view_name,
     "mode" => mode,
     "json" => {
       "name" => view_name,
       "mode" => mode
     }.to_json
   }
   @client.api_post_request("/createView", initial_post_params)
end

...which I call with:

@client.view.create('Pipelines', 'nestedview', 'hudson.plugins.nested_view.NestedView')

...which will successfully create the empty nest view. However, creating the view-in-a-view requires we POST to the API at /view/Pipelines/createView?name=project_name (substitute 'Pipelines' for the name of the nest view created above, and 'project_name' for the name of the Build Pipeline View you want to create). Here I can't see a sensible way to do this without doing something a bit too specific to my personal needs.

Is there a way around all this? I'd really prefer not to resort to using api_post_request unless I really have to!

coofercat avatar May 23 '14 10:05 coofercat

@coofercat Is this Pipeline view feature provided by a specific Jenkins plugin? If you think it is a useful feature, you could create a create_nested_view method and use the logic you mentioned above to make the correct POST call to create nested views. I would be glad to accept a PR.

If this feature is only available after installing a plugin, just make sure that it is documented well.

Let me know if you have any other questions.

arangamani avatar Jun 23 '14 08:06 arangamani