Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete Views under Jenkins without affecting existing jobs

Tags:

jenkins

groovy

I want to delete Views under Jenkins without affecting the Jobs under the view. I am asking this since 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.

BE AWARE the following scriptlet deletes all your jobs!!!

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

enter image description here

like image 497
asur Avatar asked Feb 03 '17 08:02

asur


2 Answers

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 : )

like image 77
Alex O Avatar answered Oct 14 '22 03:10

Alex O


go to view --> edit view --> unchecked all jobs on that view --> Save --> Delete View

like image 28
Avinash Avatar answered Oct 14 '22 03:10

Avinash