Bhave Bhave - 4 years ago 226
Groovy Question

How to delete Views under Jenkins without effecting existing jobs

I want to delete Views under Jenkins without effecting the Jobs under the view. I am asking this why as I am not able to Enter same name of View even after deleting this as an Administrator.

I checked Config file under Jenkins folder and tried editing the View name but that didn't work.

I need a confirmation whether below script will delete the View name only or along with Jobs under view.

Jenkins.instance.getView("MyView").items.each { item ->
println "deleting $item.name"
item.delete()
}


enter image description here

Answer Source

For deleting a view (and not touching any jobs therein) use

def view = Jenkins.instance.getView("MyView")
Jenkins.instance.deleteView( view )

Your code deletes the jobs in the view (but not the view itself), so be careful with that : )

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download