wom wom - 3 months ago 14
Groovy Question

How to set a Views description in Groovy

I'm dynamically creating a view via Groovy with..

Jenkins.instance.getItem('my_folder').addView(new ListView('MyNewView')


This works great; and I then add a filter to this view via..

Jenkins.instance.getItem('my_folder').getView('MyNewView').setIncludeRegex('.*NewView.*'


Which also works wonderfully. How would I then programmatically set the views description? I assume there's some combination I can do with

doSubmitDescription(...?)


But I haven't been able to sus it out.. Any help would be appreciated.

My current plan is to work around this by posting to
getView('MyNewView').getURL()+"/submitDescription...";


but it should be much cleaner than that..

Answer

If you want to update the view's description, here is the line you are looking for:

import org.kohsuke.stapler.StaplerRequest
import org.kohsuke.stapler.StaplerResponse

Jenkins.instance.getView('MyNewView').doSubmitDescription([ getParameter: { return "My description"; }] as StaplerRequest, [ sendRedirect: { return; } ] as StaplerResponse)